From 380afada1de5b97284704163638aafea5f0f0b0d Mon Sep 17 00:00:00 2001 From: James Moger Date: Thu, 10 May 2012 09:16:14 -0400 Subject: [PATCH] Changed constants and fixed nullpointer in update repository --- distrib/gitblit.properties | 27 ++++---- docs/04_releases.mkd | 6 ++ src/com/gitblit/Constants.java | 4 +- src/com/gitblit/GitBlit.java | 62 +++++++++++-------- .../gitblit/tests/RepositoryModelTest.java | 35 ++++++----- 5 files changed, 80 insertions(+), 54 deletions(-) diff --git a/distrib/gitblit.properties b/distrib/gitblit.properties index e04f2c8f..6353696e 100644 --- a/distrib/gitblit.properties +++ b/distrib/gitblit.properties @@ -91,6 +91,21 @@ groovy.preReceiveScripts = # SINCE 0.8.0 groovy.postReceiveScripts = +# Repository custom fields for Groovy Hook mechanism +# +# List of key=label pairs of custom fields to prompt for in the Edit Repository +# page. These keys are stored in the repository's git config file in the +# section [gitblit "customFields"]. Key names are alphanumeric only. These +# fields are intended to be used for the Groovy hook mechanism where a script +# can adjust it's execution based on the custom fields stored in the repository +# config. +# +# e.g. "commitMsgRegex=Commit Message Regular Expression" anotherProperty=Another +# +# SPACE-DELIMITED +# SINCE 1.0.0 +groovy.customFields = + # # Authentication Settings # @@ -815,14 +830,4 @@ server.storePassword = gitblit # # SINCE 0.5.0 # RESTART REQUIRED -server.shutdownPort = 8081 - -# Custom Defined Properties for Repositories -# Space delimited (use quotes if labels have spaces) list of custom properties -# to show up on the "Edit Repository" page, with labels. Thes custom properties will -# then be available for hooks. -# -# E.g. "commit-msg-regex=Commit Message Regualar Expression" another-property=Another -# -# SINCE 1.0.0 -repository.customFields = \ No newline at end of file +server.shutdownPort = 8081 \ No newline at end of file diff --git a/docs/04_releases.mkd b/docs/04_releases.mkd index cf65ea04..5bad8516 100644 --- a/docs/04_releases.mkd +++ b/docs/04_releases.mkd @@ -4,6 +4,10 @@ **%VERSION%** ([go](http://code.google.com/p/gitblit/downloads/detail?name=%GO%) | [war](http://code.google.com/p/gitblit/downloads/detail?name=%WAR%) | [express](http://code.google.com/p/gitblit/downloads/detail?name=%EXPRESS%) | [fedclient](http://code.google.com/p/gitblit/downloads/detail?name=%FEDCLIENT%) | [manager](http://code.google.com/p/gitblit/downloads/detail?name=%MANAGER%) | [api](http://code.google.com/p/gitblit/downloads/detail?name=%API%)) based on [%JGIT%][jgit]   *released %BUILDDATE%* +#### fixes + +- Fixed bug in Basic authentication if passwords had a colon (Github/peterloron) + #### changes - IUserService interface has changed to better accomodate custom authentication and/or custom authorization @@ -11,6 +15,8 @@ #### additions - Added LDAP User Service with many new *realm.ldap* keys (Github/jcrygier) +- Added support for custom repository properties for Groovy hooks (Github/jcrygier) +- Added script to facilicate proxy environment setup on Linux (Github/mragab) **0.9.3** *released 2012-04-11* diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index 80e77993..b11505c0 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -72,9 +72,9 @@ public class Constants { public static final String DEFAULT_BRANCH = "default"; - public static String CUSTOM_FIELDS_PROP_SECTION = "gitblit"; + public static final String CONFIG_GITBLIT = "gitblit"; - public static String CUSTOM_FIELDS_PROP_SUBSECTION = "customFields"; + public static final String CONFIG_CUSTOM_FIELDS = "customFields"; public static String getGitBlitVersion() { return NAME + " v" + VERSION; diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 273ad366..57421a31 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -846,22 +846,22 @@ public class GitBlit implements ServletContextListener { model.federationStrategy = FederationStrategy.fromName(getConfig(config, "federationStrategy", null)); model.federationSets = new ArrayList(Arrays.asList(config.getStringList( - "gitblit", null, "federationSets"))); + Constants.CONFIG_GITBLIT, null, "federationSets"))); model.isFederated = getConfig(config, "isFederated", false); model.origin = config.getString("remote", "origin", "url"); model.preReceiveScripts = new ArrayList(Arrays.asList(config.getStringList( - "gitblit", null, "preReceiveScript"))); + Constants.CONFIG_GITBLIT, null, "preReceiveScript"))); model.postReceiveScripts = new ArrayList(Arrays.asList(config.getStringList( - "gitblit", null, "postReceiveScript"))); + Constants.CONFIG_GITBLIT, null, "postReceiveScript"))); model.mailingLists = new ArrayList(Arrays.asList(config.getStringList( - "gitblit", null, "mailingList"))); + Constants.CONFIG_GITBLIT, null, "mailingList"))); model.indexedBranches = new ArrayList(Arrays.asList(config.getStringList( - "gitblit", null, "indexBranch"))); + Constants.CONFIG_GITBLIT, null, "indexBranch"))); // Custom defined properties model.customFields = new HashMap(); - for (String aProperty : config.getNames(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION)) { - model.customFields.put(aProperty, config.getString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, aProperty)); + for (String aProperty : config.getNames(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS)) { + model.customFields.put(aProperty, config.getString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, aProperty)); } } model.HEAD = JGitUtils.getHEADRef(r); @@ -956,7 +956,7 @@ public class GitBlit implements ServletContextListener { * @return field value or defaultValue */ private String getConfig(StoredConfig config, String field, String defaultValue) { - String value = config.getString("gitblit", null, field); + String value = config.getString(Constants.CONFIG_GITBLIT, null, field); if (StringUtils.isEmpty(value)) { return defaultValue; } @@ -964,7 +964,7 @@ public class GitBlit implements ServletContextListener { } /** - * Returns the gitblit boolean vlaue for the specified key. If key is not + * Returns the gitblit boolean value for the specified key. If key is not * set, returns defaultValue. * * @param config @@ -973,7 +973,7 @@ public class GitBlit implements ServletContextListener { * @return field value or defaultValue */ private boolean getConfig(StoredConfig config, String field, boolean defaultValue) { - return config.getBoolean("gitblit", field, defaultValue); + return config.getBoolean(Constants.CONFIG_GITBLIT, field, defaultValue); } /** @@ -1090,19 +1090,19 @@ public class GitBlit implements ServletContextListener { */ public void updateConfiguration(Repository r, RepositoryModel repository) { StoredConfig config = JGitUtils.readConfig(r); - config.setString("gitblit", null, "description", repository.description); - config.setString("gitblit", null, "owner", repository.owner); - config.setBoolean("gitblit", null, "useTickets", repository.useTickets); - config.setBoolean("gitblit", null, "useDocs", repository.useDocs); - config.setString("gitblit", null, "accessRestriction", repository.accessRestriction.name()); - config.setBoolean("gitblit", null, "showRemoteBranches", repository.showRemoteBranches); - config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen); - config.setBoolean("gitblit", null, "showReadme", repository.showReadme); - config.setBoolean("gitblit", null, "skipSizeCalculation", repository.skipSizeCalculation); - config.setBoolean("gitblit", null, "skipSummaryMetrics", repository.skipSummaryMetrics); - config.setString("gitblit", null, "federationStrategy", + config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description); + config.setString(Constants.CONFIG_GITBLIT, null, "owner", repository.owner); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "useTickets", repository.useTickets); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "useDocs", repository.useDocs); + config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name()); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "showReadme", repository.showReadme); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics); + config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy", repository.federationStrategy.name()); - config.setBoolean("gitblit", null, "isFederated", repository.isFederated); + config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated); updateList(config, "federationSets", repository.federationSets); updateList(config, "preReceiveScript", repository.preReceiveScripts); @@ -1111,8 +1111,18 @@ public class GitBlit implements ServletContextListener { updateList(config, "indexBranch", repository.indexedBranches); // User Defined Properties - for (Entry singleProperty : repository.customFields.entrySet()) { - config.setString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, singleProperty.getKey(), singleProperty.getValue()); + if (repository.customFields != null) { + if (repository.customFields.size() == 0) { + // clear section + config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); + } else { + for (Entry property : repository.customFields.entrySet()) { + // set field + String key = property.getKey(); + String value = property.getValue(); + config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, key, value); + } + } } try { @@ -1129,9 +1139,9 @@ public class GitBlit implements ServletContextListener { return; } if (ArrayUtils.isEmpty(list)) { - config.unset("gitblit", null, field); + config.unset(Constants.CONFIG_GITBLIT, null, field); } else { - config.setStringList("gitblit", null, field, list); + config.setStringList(Constants.CONFIG_GITBLIT, null, field, list); } } diff --git a/tests/com/gitblit/tests/RepositoryModelTest.java b/tests/com/gitblit/tests/RepositoryModelTest.java index 3596c333..d49cb434 100644 --- a/tests/com/gitblit/tests/RepositoryModelTest.java +++ b/tests/com/gitblit/tests/RepositoryModelTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2012 John Crygier + * Copyright 2012 gitblit.com + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package com.gitblit.tests; import static org.junit.Assert.assertEquals; @@ -17,28 +33,17 @@ import com.gitblit.utils.JGitUtils; public class RepositoryModelTest { - private static String oldSection; - private static String oldSubSection; private static boolean wasStarted = false; @BeforeClass public static void startGitBlit() throws Exception { wasStarted = GitBlitSuite.startGitblit() == false; - - oldSection = Constants.CUSTOM_FIELDS_PROP_SECTION; - oldSubSection = Constants.CUSTOM_FIELDS_PROP_SUBSECTION; - - Constants.CUSTOM_FIELDS_PROP_SECTION = "RepositoryModelTest"; - Constants.CUSTOM_FIELDS_PROP_SUBSECTION = "RepositoryModelTestSubSection"; } @AfterClass public static void stopGitBlit() throws Exception { if (wasStarted == false) GitBlitSuite.stopGitblit(); - - Constants.CUSTOM_FIELDS_PROP_SECTION = oldSection; - Constants.CUSTOM_FIELDS_PROP_SUBSECTION = oldSubSection; } @Before @@ -46,9 +51,9 @@ public class RepositoryModelTest { Repository r = GitBlitSuite.getHelloworldRepository(); StoredConfig config = JGitUtils.readConfig(r); - config.unsetSection(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION); - config.setString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, "commitMessageRegEx", "\\d"); - config.setString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, "anotherProperty", "Hello"); + config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); + config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "commitMessageRegEx", "\\d"); + config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, "anotherProperty", "Hello"); config.save(); } @@ -58,7 +63,7 @@ public class RepositoryModelTest { Repository r = GitBlitSuite.getHelloworldRepository(); StoredConfig config = JGitUtils.readConfig(r); - config.unsetSection(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION); + config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS); config.save(); } -- 2.39.5