model.federationStrategy = FederationStrategy.fromName(getConfig(config,\r
"federationStrategy", null));\r
model.federationSets = new ArrayList<String>(Arrays.asList(config.getStringList(\r
- "gitblit", null, "federationSets")));\r
+ Constants.CONFIG_GITBLIT, null, "federationSets")));\r
model.isFederated = getConfig(config, "isFederated", false);\r
model.origin = config.getString("remote", "origin", "url");\r
model.preReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(\r
- "gitblit", null, "preReceiveScript")));\r
+ Constants.CONFIG_GITBLIT, null, "preReceiveScript")));\r
model.postReceiveScripts = new ArrayList<String>(Arrays.asList(config.getStringList(\r
- "gitblit", null, "postReceiveScript")));\r
+ Constants.CONFIG_GITBLIT, null, "postReceiveScript")));\r
model.mailingLists = new ArrayList<String>(Arrays.asList(config.getStringList(\r
- "gitblit", null, "mailingList")));\r
+ Constants.CONFIG_GITBLIT, null, "mailingList")));\r
model.indexedBranches = new ArrayList<String>(Arrays.asList(config.getStringList(\r
- "gitblit", null, "indexBranch")));\r
+ Constants.CONFIG_GITBLIT, null, "indexBranch")));\r
\r
// Custom defined properties\r
model.customFields = new HashMap<String, String>();\r
- for (String aProperty : config.getNames(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION)) {\r
- model.customFields.put(aProperty, config.getString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, aProperty));\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
}\r
model.HEAD = JGitUtils.getHEADRef(r);\r
* @return field value or defaultValue\r
*/\r
private String getConfig(StoredConfig config, String field, String defaultValue) {\r
- String value = config.getString("gitblit", null, field);\r
+ String value = config.getString(Constants.CONFIG_GITBLIT, null, field);\r
if (StringUtils.isEmpty(value)) {\r
return defaultValue;\r
}\r
}\r
\r
/**\r
- * Returns the gitblit boolean vlaue for the specified key. If key is not\r
+ * Returns the gitblit boolean value for the specified key. If key is not\r
* set, returns defaultValue.\r
* \r
* @param config\r
* @return field value or defaultValue\r
*/\r
private boolean getConfig(StoredConfig config, String field, boolean defaultValue) {\r
- return config.getBoolean("gitblit", field, defaultValue);\r
+ return config.getBoolean(Constants.CONFIG_GITBLIT, field, defaultValue);\r
}\r
\r
/**\r
*/\r
public void updateConfiguration(Repository r, RepositoryModel repository) {\r
StoredConfig config = JGitUtils.readConfig(r);\r
- config.setString("gitblit", null, "description", repository.description);\r
- config.setString("gitblit", null, "owner", repository.owner);\r
- config.setBoolean("gitblit", null, "useTickets", repository.useTickets);\r
- config.setBoolean("gitblit", null, "useDocs", repository.useDocs);\r
- config.setString("gitblit", null, "accessRestriction", repository.accessRestriction.name());\r
- config.setBoolean("gitblit", null, "showRemoteBranches", repository.showRemoteBranches);\r
- config.setBoolean("gitblit", null, "isFrozen", repository.isFrozen);\r
- config.setBoolean("gitblit", null, "showReadme", repository.showReadme);\r
- config.setBoolean("gitblit", null, "skipSizeCalculation", repository.skipSizeCalculation);\r
- config.setBoolean("gitblit", null, "skipSummaryMetrics", repository.skipSummaryMetrics);\r
- config.setString("gitblit", null, "federationStrategy",\r
+ config.setString(Constants.CONFIG_GITBLIT, null, "description", repository.description);\r
+ config.setString(Constants.CONFIG_GITBLIT, null, "owner", repository.owner);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "useTickets", repository.useTickets);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "useDocs", repository.useDocs);\r
+ config.setString(Constants.CONFIG_GITBLIT, null, "accessRestriction", repository.accessRestriction.name());\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "showRemoteBranches", repository.showRemoteBranches);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFrozen", repository.isFrozen);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "showReadme", repository.showReadme);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSizeCalculation", repository.skipSizeCalculation);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "skipSummaryMetrics", repository.skipSummaryMetrics);\r
+ config.setString(Constants.CONFIG_GITBLIT, null, "federationStrategy",\r
repository.federationStrategy.name());\r
- config.setBoolean("gitblit", null, "isFederated", repository.isFederated);\r
+ config.setBoolean(Constants.CONFIG_GITBLIT, null, "isFederated", repository.isFederated);\r
\r
updateList(config, "federationSets", repository.federationSets);\r
updateList(config, "preReceiveScript", repository.preReceiveScripts);\r
updateList(config, "indexBranch", repository.indexedBranches);\r
\r
// User Defined Properties\r
- for (Entry<String, String> singleProperty : repository.customFields.entrySet()) {\r
- config.setString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, singleProperty.getKey(), singleProperty.getValue());\r
+ if (repository.customFields != null) {\r
+ if (repository.customFields.size() == 0) {\r
+ // clear section\r
+ config.unsetSection(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS);\r
+ } else {\r
+ for (Entry<String, String> property : repository.customFields.entrySet()) {\r
+ // set field\r
+ String key = property.getKey();\r
+ String value = property.getValue();\r
+ config.setString(Constants.CONFIG_GITBLIT, Constants.CONFIG_CUSTOM_FIELDS, key, value);\r
+ }\r
+ }\r
}\r
\r
try {\r
return;\r
}\r
if (ArrayUtils.isEmpty(list)) {\r
- config.unset("gitblit", null, field);\r
+ config.unset(Constants.CONFIG_GITBLIT, null, field);\r
} else {\r
- config.setStringList("gitblit", null, field, list);\r
+ config.setStringList(Constants.CONFIG_GITBLIT, null, field, list);\r
}\r
}\r
\r
+/*
+ * 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;
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
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();
}
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();
}