| | |
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collection;
|
| | | import java.util.Collections;
|
| | | import java.util.HashMap;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | | import java.util.TreeMap;
|
| | | import java.util.concurrent.ConcurrentHashMap;
|
| | | import java.util.concurrent.Executors;
|
| | | import java.util.concurrent.ScheduledExecutorService;
|
| | |
| | | import com.gitblit.models.Metric;
|
| | | import com.gitblit.models.ObjectCache;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.models.ServerSettings;
|
| | | import com.gitblit.models.ServerStatus;
|
| | | import com.gitblit.models.SettingModel;
|
| | | import com.gitblit.models.UserModel;
|
| | |
| | |
|
| | | private IStoredSettings settings;
|
| | |
|
| | | private Map<String, SettingModel> settingModels;
|
| | | private ServerSettings settingsModel;
|
| | |
|
| | | private ServerStatus serverStatus;
|
| | |
|
| | |
| | | */
|
| | | public static boolean isDebugMode() {
|
| | | return self().settings.getBoolean(Keys.web.debugMode, false);
|
| | | }
|
| | |
|
| | | /**
|
| | | * Updates the list of server settings.
|
| | | * |
| | | * @param settings
|
| | | * @return true if the update succeeded
|
| | | */
|
| | | public boolean updateSettings(Collection<SettingModel> settings) {
|
| | | // TODO update the settings
|
| | | return false;
|
| | | }
|
| | |
|
| | | public ServerStatus getStatus() {
|
| | |
| | | */
|
| | | public void updateUserModel(String username, UserModel user, boolean isCreate)
|
| | | throws GitBlitException {
|
| | | if (!username.equalsIgnoreCase(user.username)) {
|
| | | if (userService.getUserModel(user.username) != null) {
|
| | | throw new GitBlitException(MessageFormat.format(
|
| | | "Failed to rename ''{0}'' because ''{1}'' already exists.", username,
|
| | | user.username));
|
| | | }
|
| | | }
|
| | | if (!userService.updateUserModel(username, user)) {
|
| | | throw new GitBlitException(isCreate ? "Failed to add user!" : "Failed to update user!");
|
| | | }
|
| | |
| | | model.isFrozen = getConfig(config, "isFrozen", false);
|
| | | model.showReadme = getConfig(config, "showReadme", false);
|
| | | model.skipSizeCalculation = getConfig(config, "skipSizeCalculation", false);
|
| | | model.skipSummaryMetrics = getConfig(config, "skipSummaryMetrics", false);
|
| | | model.federationStrategy = FederationStrategy.fromName(getConfig(config,
|
| | | "federationStrategy", null));
|
| | | model.federationSets = new ArrayList<String>(Arrays.asList(config.getStringList(
|
| | |
| | | } else {
|
| | | // rename repository
|
| | | if (!repositoryName.equalsIgnoreCase(repository.name)) {
|
| | | if (!repository.name.toLowerCase().endsWith(
|
| | | org.eclipse.jgit.lib.Constants.DOT_GIT_EXT)) {
|
| | | repository.name += org.eclipse.jgit.lib.Constants.DOT_GIT_EXT;
|
| | | }
|
| | | if (new File(repositoriesFolder, repository.name).exists()) {
|
| | | throw new GitBlitException(MessageFormat.format(
|
| | | "Failed to rename ''{0}'' because ''{1}'' already exists.",
|
| | | repositoryName, repository.name));
|
| | | }
|
| | | closeRepository(repositoryName);
|
| | | File folder = new File(repositoriesFolder, repositoryName);
|
| | | File destFolder = new File(repositoriesFolder, repository.name);
|
| | |
| | | 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.setStringList("gitblit", null, "federationSets", repository.federationSets);
|
| | | config.setString("gitblit", null, "federationStrategy",
|
| | | repository.federationStrategy.name());
|
| | |
| | | /**
|
| | | * Returns the descriptions/comments of the Gitblit config settings.
|
| | | *
|
| | | * @return Map<String, SettingModel>
|
| | | * @return SettingsModel
|
| | | */
|
| | | public Map<String, SettingModel> getSettingModels() {
|
| | | public ServerSettings getSettingsModel() {
|
| | | // ensure that the current values are updated in the setting models
|
| | | for (String key : settings.getAllKeys(null)) {
|
| | | if (settingModels.containsKey(key)) {
|
| | | settingModels.get(key).currentValue = settings.getString(key, "");
|
| | | }
|
| | | }
|
| | | return settingModels;
|
| | | settingsModel.updateCurrentValues(settings);
|
| | | return settingsModel;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | *
|
| | | * @return Map<String, SettingModel>
|
| | | */
|
| | | private Map<String, SettingModel> loadSettingModels() {
|
| | | Map<String, SettingModel> map = new TreeMap<String, SettingModel>();
|
| | | private ServerSettings loadSettingModels() {
|
| | | ServerSettings settingsModel = new ServerSettings();
|
| | | try {
|
| | | // Read bundled Gitblit properties to extract setting descriptions.
|
| | | // This copy is pristine and only used for populating the setting
|
| | |
| | | setting.defaultValue = kvp[1].trim();
|
| | | setting.currentValue = setting.defaultValue;
|
| | | setting.description = description.toString().trim();
|
| | | map.put(key, setting);
|
| | | settingsModel.add(setting);
|
| | | description.setLength(0);
|
| | | setting = new SettingModel();
|
| | | }
|
| | |
| | | } catch (IOException e) {
|
| | | logger.error("Failed to load resource copy of gitblit.properties");
|
| | | }
|
| | | return map;
|
| | | return settingsModel;
|
| | | }
|
| | |
|
| | | /**
|
| | |
| | | @Override
|
| | | public void contextInitialized(ServletContextEvent contextEvent) {
|
| | | servletContext = contextEvent.getServletContext();
|
| | | settingModels = loadSettingModels();
|
| | | settingsModel = loadSettingModels();
|
| | | if (settings == null) {
|
| | | // Gitblit WAR is running in a servlet container
|
| | | WebXmlSettings webxmlSettings = new WebXmlSettings(contextEvent.getServletContext());
|