diff options
author | John Crygier <john.crygier@aon.com> | 2012-05-04 08:50:22 -0500 |
---|---|---|
committer | John Crygier <john.crygier@aon.com> | 2012-05-04 08:50:22 -0500 |
commit | 4a5a55229bf066bf933dde6cb6f51a4378d67fb7 (patch) | |
tree | 449b5faacf08fa7db7c71fa0b81d3ef51b842990 | |
parent | cca55e4722fa1ceba8a0933dda974162635f3955 (diff) | |
download | gitblit-4a5a55229bf066bf933dde6cb6f51a4378d67fb7.tar.gz gitblit-4a5a55229bf066bf933dde6cb6f51a4378d67fb7.zip |
Change techique for custom properties to fall in line with reading / writing of all other properties
-rw-r--r-- | src/com/gitblit/Constants.java | 4 | ||||
-rw-r--r-- | src/com/gitblit/GitBlit.java | 11 | ||||
-rw-r--r-- | src/com/gitblit/models/RepositoryModel.java | 45 | ||||
-rw-r--r-- | tests/com/gitblit/tests/RepositoryModelTest.java | 41 |
4 files changed, 40 insertions, 61 deletions
diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index bbb986b2..c84b95f1 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -72,6 +72,10 @@ public class Constants { public static final String DEFAULT_BRANCH = "default";
+ public static String CUSTOM_DEFINED_PROP_SECTION = "gitblit";
+
+ public static String CUSTOM_DEFINED_PROP_SUBSECTION = "customDefinedProperties";
+
public static String getGitBlitVersion() {
return NAME + " v" + VERSION;
}
diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 565b024a..a95e4f74 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -857,6 +857,12 @@ public class GitBlit implements ServletContextListener { "gitblit", null, "mailingList")));
model.indexedBranches = new ArrayList<String>(Arrays.asList(config.getStringList(
"gitblit", null, "indexBranch")));
+
+ // Custom defined properties
+ model.userDefinedProperties = new HashMap<String, String>();
+ for (String aProperty : config.getNames(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION)) {
+ model.userDefinedProperties.put(aProperty, config.getString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, aProperty));
+ }
}
model.HEAD = JGitUtils.getHEADRef(r);
model.availableRefs = JGitUtils.getAvailableHeadTargets(r);
@@ -1103,6 +1109,11 @@ public class GitBlit implements ServletContextListener { updateList(config, "postReceiveScript", repository.postReceiveScripts);
updateList(config, "mailingList", repository.mailingLists);
updateList(config, "indexBranch", repository.indexedBranches);
+
+ // User Defined Properties
+ for (Entry<String, String> singleProperty : repository.userDefinedProperties.entrySet()) {
+ config.setString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, singleProperty.getKey(), singleProperty.getValue());
+ }
try {
config.save();
diff --git a/src/com/gitblit/models/RepositoryModel.java b/src/com/gitblit/models/RepositoryModel.java index fd35f36f..539aa513 100644 --- a/src/com/gitblit/models/RepositoryModel.java +++ b/src/com/gitblit/models/RepositoryModel.java @@ -19,17 +19,11 @@ import java.io.Serializable; import java.util.ArrayList;
import java.util.Date;
import java.util.List;
-
-import org.eclipse.jgit.lib.Repository;
-import org.eclipse.jgit.lib.StoredConfig;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
+import java.util.Map;
import com.gitblit.Constants.AccessRestrictionType;
import com.gitblit.Constants.FederationStrategy;
-import com.gitblit.GitBlit;
import com.gitblit.utils.ArrayUtils;
-import com.gitblit.utils.JGitUtils;
import com.gitblit.utils.StringUtils;
/**
@@ -42,11 +36,6 @@ import com.gitblit.utils.StringUtils; public class RepositoryModel implements Serializable, Comparable<RepositoryModel> {
private static final long serialVersionUID = 1L;
-
- public static String CUSTOM_DEFINED_PROP_SECTION = "gitblit";
- public static String CUSTOM_DEFINED_PROP_SUBSECTION = "customDefinedProperties";
-
- private final Logger logger = LoggerFactory.getLogger(RepositoryModel.class);
// field names are reflectively mapped in EditRepository page
public String name;
@@ -75,6 +64,7 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel public List<String> preReceiveScripts;
public List<String> postReceiveScripts;
public List<String> mailingLists;
+ public Map<String, String> userDefinedProperties;
private String displayName;
public RepositoryModel() {
@@ -103,37 +93,6 @@ public class RepositoryModel implements Serializable, Comparable<RepositoryModel }
return localBranches;
}
-
- public String getCustomProperty(String propertyKey) {
- try {
- Repository r = GitBlit.self().getRepository(name);
- StoredConfig config = JGitUtils.readConfig(r);
-
- return config.getString(CUSTOM_DEFINED_PROP_SECTION, CUSTOM_DEFINED_PROP_SUBSECTION, propertyKey);
- } catch (Exception e) {
- logger.error("Error getting Custom Property", e);
-
- return null;
- }
- }
-
- public String setCustomProperty(String propertyKey, String propertyValue) {
- try {
- Repository r = GitBlit.self().getRepository(name);
- StoredConfig config = JGitUtils.readConfig(r);
-
- String oldValue = config.getString(CUSTOM_DEFINED_PROP_SECTION, CUSTOM_DEFINED_PROP_SUBSECTION, propertyKey);
-
- config.setString(CUSTOM_DEFINED_PROP_SECTION, CUSTOM_DEFINED_PROP_SUBSECTION, propertyKey, propertyValue);
- config.save();
-
- return oldValue;
- } catch (Exception e) {
- logger.error("Error getting Custom Property", e);
-
- return null;
- }
- }
@Override
public String toString() {
diff --git a/tests/com/gitblit/tests/RepositoryModelTest.java b/tests/com/gitblit/tests/RepositoryModelTest.java index 00bf0d0a..f7418152 100644 --- a/tests/com/gitblit/tests/RepositoryModelTest.java +++ b/tests/com/gitblit/tests/RepositoryModelTest.java @@ -1,6 +1,6 @@ package com.gitblit.tests; -import static org.junit.Assert.*; +import static org.junit.Assert.assertEquals; import org.eclipse.jgit.lib.Repository; import org.eclipse.jgit.lib.StoredConfig; @@ -10,6 +10,7 @@ import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; +import com.gitblit.Constants; import com.gitblit.GitBlit; import com.gitblit.models.RepositoryModel; import com.gitblit.utils.JGitUtils; @@ -24,11 +25,11 @@ public class RepositoryModelTest { public static void startGitBlit() throws Exception { wasStarted = GitBlitSuite.startGitblit() == false; - oldSection = RepositoryModel.CUSTOM_DEFINED_PROP_SECTION; - oldSubSection = RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION; + oldSection = Constants.CUSTOM_DEFINED_PROP_SECTION; + oldSubSection = Constants.CUSTOM_DEFINED_PROP_SUBSECTION; - RepositoryModel.CUSTOM_DEFINED_PROP_SECTION = "RepositoryModelTest"; - RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION = "RepositoryModelTestSubSection"; + Constants.CUSTOM_DEFINED_PROP_SECTION = "RepositoryModelTest"; + Constants.CUSTOM_DEFINED_PROP_SUBSECTION = "RepositoryModelTestSubSection"; } @AfterClass @@ -36,8 +37,8 @@ public class RepositoryModelTest { if (wasStarted == false) GitBlitSuite.stopGitblit(); - RepositoryModel.CUSTOM_DEFINED_PROP_SECTION = oldSection; - RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION = oldSubSection; + Constants.CUSTOM_DEFINED_PROP_SECTION = oldSection; + Constants.CUSTOM_DEFINED_PROP_SUBSECTION = oldSubSection; } @Before @@ -45,9 +46,9 @@ public class RepositoryModelTest { Repository r = GitBlitSuite.getHelloworldRepository(); StoredConfig config = JGitUtils.readConfig(r); - config.unsetSection(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION); - config.setString(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION, "commitMessageRegEx", "\\d"); - config.setString(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION, "anotherProperty", "Hello"); + config.unsetSection(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION); + config.setString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, "commitMessageRegEx", "\\d"); + config.setString(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION, "anotherProperty", "Hello"); config.save(); } @@ -57,7 +58,7 @@ public class RepositoryModelTest { Repository r = GitBlitSuite.getHelloworldRepository(); StoredConfig config = JGitUtils.readConfig(r); - config.unsetSection(RepositoryModel.CUSTOM_DEFINED_PROP_SECTION, RepositoryModel.CUSTOM_DEFINED_PROP_SUBSECTION); + config.unsetSection(Constants.CUSTOM_DEFINED_PROP_SECTION, Constants.CUSTOM_DEFINED_PROP_SUBSECTION); config.save(); } @@ -66,8 +67,8 @@ public class RepositoryModelTest { RepositoryModel model = GitBlit.self().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); - assertEquals("\\d", model.getCustomProperty("commitMessageRegEx")); - assertEquals("Hello", model.getCustomProperty("anotherProperty")); + assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); + assertEquals("Hello", model.userDefinedProperties.get("anotherProperty")); } @Test @@ -75,13 +76,17 @@ public class RepositoryModelTest { RepositoryModel model = GitBlit.self().getRepositoryModel( GitBlitSuite.getHelloworldRepository().getDirectory().getName()); - assertEquals("\\d", model.getCustomProperty("commitMessageRegEx")); - assertEquals("Hello", model.getCustomProperty("anotherProperty")); + assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); + assertEquals("Hello", model.userDefinedProperties.get("anotherProperty")); - assertEquals("Hello", model.setCustomProperty("anotherProperty", "GoodBye")); + assertEquals("Hello", model.userDefinedProperties.put("anotherProperty", "GoodBye")); + GitBlit.self().updateRepositoryModel(model.name, model, false); - assertEquals("\\d", model.getCustomProperty("commitMessageRegEx")); - assertEquals("GoodBye", model.getCustomProperty("anotherProperty")); + model = GitBlit.self().getRepositoryModel( + GitBlitSuite.getHelloworldRepository().getDirectory().getName()); + + assertEquals("\\d", model.userDefinedProperties.get("commitMessageRegEx")); + assertEquals("GoodBye", model.userDefinedProperties.get("anotherProperty")); } } |