From 84c1d5c1527183a4e2830deab5b177d880914f1c Mon Sep 17 00:00:00 2001 From: James Moger Date: Sat, 22 Oct 2011 09:01:20 -0400 Subject: [PATCH] Documentation. Refactoring class names. Re-encapsulate settings. --- docs/01_setup.mkd | 1 + docs/02_rpc.mkd | 77 ++++++++++++++----- src/com/gitblit/Constants.java | 2 +- src/com/gitblit/GitBlit.java | 26 +++---- src/com/gitblit/RpcServlet.java | 4 +- src/com/gitblit/client/EditUserDialog.java | 19 +++-- .../{GitblitModel.java => GitblitClient.java} | 21 +++-- src/com/gitblit/client/GitblitPanel.java | 68 ++++++++-------- .../gitblit/client/RegistrationsDialog.java | 6 +- ...odel.java => RegistrationsTableModel.java} | 4 +- ...Model.java => RepositoriesTableModel.java} | 6 +- ...ingsModel.java => SettingsTableModel.java} | 14 ++-- .../{UsersModel.java => UsersTableModel.java} | 6 +- src/com/gitblit/models/ServerSettings.java | 63 +++++++++++++++ src/com/gitblit/models/ServerStatus.java | 10 +-- src/com/gitblit/utils/RpcUtils.java | 16 ++-- tests/com/gitblit/tests/RpcTests.java | 4 +- 17 files changed, 224 insertions(+), 123 deletions(-) rename src/com/gitblit/client/{GitblitModel.java => GitblitClient.java} (88%) rename src/com/gitblit/client/{RegistrationsModel.java => RegistrationsTableModel.java} (90%) rename src/com/gitblit/client/{RepositoriesModel.java => RepositoriesTableModel.java} (90%) rename src/com/gitblit/client/{SettingsModel.java => SettingsTableModel.java} (84%) rename src/com/gitblit/client/{UsersModel.java => UsersTableModel.java} (89%) create mode 100644 src/com/gitblit/models/ServerSettings.java diff --git a/docs/01_setup.mkd b/docs/01_setup.mkd index c7a8ff61..b2c5b2f8 100644 --- a/docs/01_setup.mkd +++ b/docs/01_setup.mkd @@ -134,6 +134,7 @@ All repository settings are stored within the repository `.git/config` file unde showReadme = false federationStrategy = FEDERATE_THIS isFederated = false + skipSizeCalculation = false federationSets = #### Repository Names diff --git a/docs/02_rpc.mkd b/docs/02_rpc.mkd index b01eb679..94739ca3 100644 --- a/docs/02_rpc.mkd +++ b/docs/02_rpc.mkd @@ -30,7 +30,8 @@ The Gitblit RPC mechanism, like the Gitblit JGit servlet, syndication/feed servl LIST_FEDERATION_RESULTS-admin-List<FederationModel> LIST_FEDERATION_PROPOSALS-admin-List<FederationProposal> LIST_FEDERATION_SETS-admin-List<FederationSet> -LIST_SETTINGS-admin-Map<String, SettingModel> +LIST_SETTINGS-admin-ServerSettings (see example below) +LIST_STATUS-admin-ServerStatus (see example below) ### RPC/HTTP Response Codes @@ -55,6 +56,8 @@ One obvious goal of a Gitblit RPC mechanism would be to have an EGit Feature tha This particular project should not be difficult as the only external dependency for `com.gitblit.utils.RpcUtils` is [google-gson](http://google-gson.googlecode.com) which is already a dependency of the EGit/GitHub Mylyn feature. +One proposal from the EGit team is to define a common JSON RPC method for enumeration of repositories which can be implemented by Git hosts. The EGit team would then implement the UI and the client-side enumeration code. This idea was raised as part of this [feature request for EGit](https://bugs.eclipse.org/bugs/show_bug.cgi?id=361251). + Currently this project is in the planning stage. ### Example: LIST_REPOSITORIES @@ -80,6 +83,7 @@ Currently this project is in the planning stage. "libraries" ], "isFederated": false, + "skipSizeCalculation": false, "size": "102 KB" }, "https://localhost/git/libraries/smack.git": { @@ -97,6 +101,7 @@ Currently this project is in the planning stage. "federationStrategy": "FEDERATE_THIS", "federationSets": [], "isFederated": false, + "skipSizeCalculation": false, "size": "4.8 MB" } } @@ -157,28 +162,58 @@ The original repository name is specified in the *name* url parameter. The new ### Example: LIST_SETTINGS **url**: https://localhost/rpc?req=LIST_SETTINGS -**response body**: Map<String, SettingModel> +**response body**: ServerSettings
 {
-  "web.siteName": {
-    "name": "web.siteName",
-    "currentValue": "",
-    "defaultValue": "",
-    "description": "Gitblit Web Settings\nIf blank Gitblit is displayed.",
-    "since": "0.5.0",
-    "caseSensitive": false,
-    "restartRequired": false,
-    "spaceDelimited": false
-  },
-  "web.summaryCommitCount": {
-    "name": "web.summaryCommitCount",
-    "currentValue": "16",
-    "defaultValue": "16",
-    "description": "The number of commits to display on the summary page\nValue must exceed 0 else default of 16 is used",
-    "since": "0.5.0",
-    "caseSensitive": false,
-    "restartRequired": false,
-    "spaceDelimited": false
+  "settings": {
+      "web.siteName": {
+        "name": "web.siteName",
+        "currentValue": "",
+        "defaultValue": "",
+        "description": "Gitblit Web Settings\nIf blank Gitblit is displayed.",
+        "since": "0.5.0",
+        "caseSensitive": false,
+        "restartRequired": false,
+        "spaceDelimited": false
+      },
+      "web.summaryCommitCount": {
+        "name": "web.summaryCommitCount",
+        "currentValue": "16",
+        "defaultValue": "16",
+        "description": "The number of commits to display on the summary page\nValue must exceed 0 else default of 16 is used",
+        "since": "0.5.0",
+        "caseSensitive": false,
+        "restartRequired": false,
+        "spaceDelimited": false
+      }
   }
 }
+
+ +### Example: LIST_STATUS +**url**: https://localhost/rpc?req=LIST_STATUS +**response body**: ServerStatus +
+{
+  "bootDate": "2011-10-22T12:13:00Z",
+  "systemProperties": {
+    "file.encoding": "Cp1252",
+    "java.home": "C:\\Program Files\\Java\\jdk1.6.0_26\\jre",
+    "java.io.tmpdir": "C:\\Users\\JAMESM~1\\AppData\\Local\\Temp\\",
+    "java.runtime.name": "Java(TM) SE Runtime Environment",
+    "java.runtime.version": "1.6.0_26-b03",
+    "java.vendor": "Sun Microsystems Inc.",
+    "java.version": "1.6.0_26",
+    "java.vm.info": "mixed mode",
+    "java.vm.name": "Java HotSpot(TM) 64-Bit Server VM",
+    "java.vm.vendor": "Sun Microsystems Inc.",
+    "java.vm.version": "20.1-b02",
+    "os.arch": "amd64",
+    "os.name": "Windows 7",
+    "os.version": "6.1"
+  },
+  "heapAllocated": 128057344,
+  "heapFree": 120399168,
+  "heapSize": 1899560960
+}
 
\ No newline at end of file diff --git a/src/com/gitblit/Constants.java b/src/com/gitblit/Constants.java index f3ff6c44..79dfaf6a 100644 --- a/src/com/gitblit/Constants.java +++ b/src/com/gitblit/Constants.java @@ -205,7 +205,7 @@ public class Constants { LIST_USERS, CREATE_USER, EDIT_USER, DELETE_USER, LIST_REPOSITORY_MEMBERS, SET_REPOSITORY_MEMBERS, LIST_FEDERATION_REGISTRATIONS, LIST_FEDERATION_RESULTS, LIST_FEDERATION_PROPOSALS, LIST_FEDERATION_SETS, LIST_SETTINGS, - LIST_SERVER_STATUS; + LIST_STATUS; public static RpcRequest fromName(String name) { for (RpcRequest type : values()) { diff --git a/src/com/gitblit/GitBlit.java b/src/com/gitblit/GitBlit.java index 238c01f7..eaf6a957 100644 --- a/src/com/gitblit/GitBlit.java +++ b/src/com/gitblit/GitBlit.java @@ -30,7 +30,6 @@ 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; @@ -70,6 +69,7 @@ import com.gitblit.models.ObjectCache; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerStatus; import com.gitblit.models.SettingModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.UserModel; import com.gitblit.utils.ByteFormat; import com.gitblit.utils.FederationUtils; @@ -123,7 +123,7 @@ public class GitBlit implements ServletContextListener { private IStoredSettings settings; - private Map settingModels; + private ServerSettings settingsModel; private ServerStatus serverStatus; @@ -1275,16 +1275,12 @@ public class GitBlit implements ServletContextListener { /** * Returns the descriptions/comments of the Gitblit config settings. * - * @return Map + * @return SettingsModel */ - public Map 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; } /** @@ -1294,8 +1290,8 @@ public class GitBlit implements ServletContextListener { * * @return Map */ - private Map loadSettingModels() { - Map map = new TreeMap(); + 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 @@ -1337,7 +1333,7 @@ public class GitBlit implements ServletContextListener { 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(); } @@ -1349,7 +1345,7 @@ public class GitBlit implements ServletContextListener { } catch (IOException e) { logger.error("Failed to load resource copy of gitblit.properties"); } - return map; + return settingsModel; } /** @@ -1409,7 +1405,7 @@ public class GitBlit implements ServletContextListener { @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()); diff --git a/src/com/gitblit/RpcServlet.java b/src/com/gitblit/RpcServlet.java index 6a8c2c59..ceed35e1 100644 --- a/src/com/gitblit/RpcServlet.java +++ b/src/com/gitblit/RpcServlet.java @@ -182,8 +182,8 @@ public class RpcServlet extends JsonServlet { } } else if (RpcRequest.LIST_SETTINGS.equals(reqType)) { // return the server's settings - result = GitBlit.self().getSettingModels(); - } else if (RpcRequest.LIST_SERVER_STATUS.equals(reqType)) { + result = GitBlit.self().getSettingsModel(); + } else if (RpcRequest.LIST_STATUS.equals(reqType)) { // return the server's status information result = GitBlit.self().getStatus(); } diff --git a/src/com/gitblit/client/EditUserDialog.java b/src/com/gitblit/client/EditUserDialog.java index 0a1ddd93..988f8fb0 100644 --- a/src/com/gitblit/client/EditUserDialog.java +++ b/src/com/gitblit/client/EditUserDialog.java @@ -29,7 +29,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.HashSet; import java.util.List; -import java.util.Map; import java.util.Set; import javax.swing.ImageIcon; @@ -48,7 +47,7 @@ import javax.swing.KeyStroke; import com.gitblit.Constants.AccessRestrictionType; import com.gitblit.Keys; import com.gitblit.models.RepositoryModel; -import com.gitblit.models.SettingModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.UserModel; import com.gitblit.utils.StringUtils; @@ -58,10 +57,10 @@ public class EditUserDialog extends JDialog { private final UserModel user; - private final Map settings; + private final ServerSettings settings; private boolean isCreate; - + private boolean canceled = true; private JTextField usernameField; @@ -78,13 +77,13 @@ public class EditUserDialog extends JDialog { private Set usernames; - public EditUserDialog(Map settings) { + public EditUserDialog(ServerSettings settings) { this(new UserModel(""), settings); this.isCreate = true; - setTitle(Translation.get("gb.newUser")); + setTitle(Translation.get("gb.newUser")); } - public EditUserDialog(UserModel anUser, Map settings) { + public EditUserDialog(UserModel anUser, ServerSettings settings) { super(); this.user = new UserModel(""); this.settings = settings; @@ -95,7 +94,7 @@ public class EditUserDialog extends JDialog { setTitle(Translation.get("gb.edit") + ": " + anUser.username); setIconImage(new ImageIcon(getClass().getResource("/gitblt-favicon.png")).getImage()); } - + @Override protected JRootPane createRootPane() { KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0); @@ -203,8 +202,8 @@ public class EditUserDialog extends JDialog { } char[] pw = passwordField.getPassword(); if (pw == null || pw.length < minLength) { - error(MessageFormat.format( - "Password is too short. Minimum length is {0} characters.", minLength)); + error(MessageFormat.format("Password is too short. Minimum length is {0} characters.", + minLength)); return false; } char[] cpw = confirmPasswordField.getPassword(); diff --git a/src/com/gitblit/client/GitblitModel.java b/src/com/gitblit/client/GitblitClient.java similarity index 88% rename from src/com/gitblit/client/GitblitModel.java rename to src/com/gitblit/client/GitblitClient.java index 55e74b9c..76a67316 100644 --- a/src/com/gitblit/client/GitblitModel.java +++ b/src/com/gitblit/client/GitblitClient.java @@ -27,12 +27,19 @@ import com.gitblit.GitBlitException.UnauthorizedException; import com.gitblit.Keys; import com.gitblit.models.FederationModel; 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; import com.gitblit.utils.RpcUtils; -public class GitblitModel implements Serializable { +/** + * GitblitClient is a object that retrieves data from a Gitblit server, caches + * it for local operations, and allows updating or creating Gitblit objects. + * + * @author James Moger + * + */ +public class GitblitClient implements Serializable { private static final long serialVersionUID = 1L; @@ -44,7 +51,7 @@ public class GitblitModel implements Serializable { private volatile boolean isAdmin; - private volatile Map settings; + private volatile ServerSettings settings; private final List allRepositories; @@ -54,7 +61,7 @@ public class GitblitModel implements Serializable { private ServerStatus status; - public GitblitModel(String url, String account, char[] password) { + public GitblitClient(String url, String account, char[] password) { this.url = url; this.account = account; this.password = password; @@ -87,10 +94,14 @@ public class GitblitModel implements Serializable { return account != null && account.equalsIgnoreCase(model.owner); } - public Map getSettings() { + public ServerSettings getSettings() { return settings; } + public ServerStatus getStatus() { + return status; + } + public String getSettingDescription(String key) { return settings.get(key).description; } diff --git a/src/com/gitblit/client/GitblitPanel.java b/src/com/gitblit/client/GitblitPanel.java index 8635b006..e4c6e76c 100644 --- a/src/com/gitblit/client/GitblitPanel.java +++ b/src/com/gitblit/client/GitblitPanel.java @@ -71,21 +71,21 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private final Insets insets = new Insets(margin, margin, margin, margin); - private GitblitModel gitblit; + private GitblitClient gitblit; private JTabbedPane tabs; private JTable repositoriesTable; - private RepositoriesModel repositoriesModel; + private RepositoriesTableModel repositoriesModel; private JTable usersTable; - private UsersModel usersModel; + private UsersTableModel usersModel; private JTable settingsTable; - private SettingsModel settingsModel; + private SettingsTableModel settingsModel; private JButton createRepository; @@ -99,11 +99,11 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private DefaultTableCellRenderer sizeRenderer; - private TableRowSorter defaultRepositoriesSorter; + private TableRowSorter defaultRepositoriesSorter; - private TableRowSorter defaultUsersSorter; + private TableRowSorter defaultUsersSorter; - private TableRowSorter defaultSettingsSorter; + private TableRowSorter defaultSettingsSorter; private JButton editRepository; @@ -112,7 +112,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } public GitblitPanel(String url, String account, char[] password) { - this.gitblit = new GitblitModel(url, account, password); + this.gitblit = new GitblitClient(url, account, password); tabs = new JTabbedPane(JTabbedPane.BOTTOM); tabs.addTab(Translation.get("gb.repositories"), createRepositoriesPanel()); @@ -180,17 +180,17 @@ public class GitblitPanel extends JPanel implements CloseTabListener { ownerRenderer.setForeground(Color.gray); ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER); - repositoriesModel = new RepositoriesModel(); - defaultRepositoriesSorter = new TableRowSorter(repositoriesModel); + repositoriesModel = new RepositoriesTableModel(); + defaultRepositoriesSorter = new TableRowSorter(repositoriesModel); repositoriesTable = Utils.newTable(repositoriesModel); repositoriesTable.setRowHeight(nameRenderer.getFont().getSize() + 8); repositoriesTable.setRowSorter(defaultRepositoriesSorter); - repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesModel.Columns.Name.ordinal()); + repositoriesTable.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal()); - setRepositoryRenderer(RepositoriesModel.Columns.Name, nameRenderer, -1); - setRepositoryRenderer(RepositoriesModel.Columns.Indicators, typeRenderer, 100); - setRepositoryRenderer(RepositoriesModel.Columns.Owner, ownerRenderer, -1); - setRepositoryRenderer(RepositoriesModel.Columns.Size, sizeRenderer, 60); + setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1); + setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100); + setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1); + setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60); repositoriesTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -205,7 +205,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { if (selected) { int viewRow = repositoriesTable.getSelectedRow(); int modelRow = repositoriesTable.convertRowIndexToModel(viewRow); - RepositoryModel model = ((RepositoriesModel) repositoriesTable.getModel()).list + RepositoryModel model = ((RepositoriesTableModel) repositoriesTable.getModel()).list .get(modelRow); editRepository.setEnabled(singleSelection && (gitblit.allowAdmin() || gitblit.isOwner(model))); @@ -266,7 +266,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return repositoriesPanel; } - private void setRepositoryRenderer(RepositoriesModel.Columns col, TableCellRenderer renderer, + private void setRepositoryRenderer(RepositoriesTableModel.Columns col, TableCellRenderer renderer, int maxWidth) { String name = repositoriesTable.getColumnName(col.ordinal()); repositoriesTable.getColumn(name).setCellRenderer(renderer); @@ -307,14 +307,14 @@ public class GitblitPanel extends JPanel implements CloseTabListener { } }); - usersModel = new UsersModel(); - defaultUsersSorter = new TableRowSorter(usersModel); + usersModel = new UsersTableModel(); + defaultUsersSorter = new TableRowSorter(usersModel); usersTable = Utils.newTable(usersModel); - String name = usersTable.getColumnName(UsersModel.Columns.Name.ordinal()); + String name = usersTable.getColumnName(UsersTableModel.Columns.Name.ordinal()); usersTable.setRowHeight(nameRenderer.getFont().getSize() + 8); usersTable.getColumn(name).setCellRenderer(nameRenderer); usersTable.setRowSorter(defaultUsersSorter); - usersTable.getRowSorter().toggleSortOrder(UsersModel.Columns.Name.ordinal()); + usersTable.getRowSorter().toggleSortOrder(UsersTableModel.Columns.Name.ordinal()); usersTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -381,15 +381,15 @@ public class GitblitPanel extends JPanel implements CloseTabListener { private JPanel createSettingsPanel() { final SettingPanel settingPanel = new SettingPanel(); - settingsModel = new SettingsModel(); - defaultSettingsSorter = new TableRowSorter(settingsModel); + settingsModel = new SettingsTableModel(); + defaultSettingsSorter = new TableRowSorter(settingsModel); settingsTable = Utils.newTable(settingsModel); settingsTable.setDefaultRenderer(SettingModel.class, new SettingCellRenderer()); - String name = settingsTable.getColumnName(UsersModel.Columns.Name.ordinal()); + String name = settingsTable.getColumnName(UsersTableModel.Columns.Name.ordinal()); settingsTable.setRowHeight(nameRenderer.getFont().getSize() + 8); settingsTable.getColumn(name).setCellRenderer(nameRenderer); settingsTable.setRowSorter(defaultSettingsSorter); - settingsTable.getRowSorter().toggleSortOrder(SettingsModel.Columns.Name.ordinal()); + settingsTable.getRowSorter().toggleSortOrder(SettingsTableModel.Columns.Name.ordinal()); settingsTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() { @Override @@ -496,8 +496,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { repositoriesTable.setRowSorter(defaultRepositoriesSorter); return; } - RowFilter containsFilter = new RowFilter() { - public boolean include(Entry entry) { + RowFilter containsFilter = new RowFilter() { + public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) { return true; @@ -506,7 +506,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return false; } }; - TableRowSorter sorter = new TableRowSorter( + TableRowSorter sorter = new TableRowSorter( repositoriesModel); sorter.setRowFilter(containsFilter); repositoriesTable.setRowSorter(sorter); @@ -517,8 +517,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { usersTable.setRowSorter(defaultUsersSorter); return; } - RowFilter containsFilter = new RowFilter() { - public boolean include(Entry entry) { + RowFilter containsFilter = new RowFilter() { + public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) { return true; @@ -527,7 +527,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return false; } }; - TableRowSorter sorter = new TableRowSorter(usersModel); + TableRowSorter sorter = new TableRowSorter(usersModel); sorter.setRowFilter(containsFilter); usersTable.setRowSorter(sorter); } @@ -537,8 +537,8 @@ public class GitblitPanel extends JPanel implements CloseTabListener { settingsTable.setRowSorter(defaultSettingsSorter); return; } - RowFilter containsFilter = new RowFilter() { - public boolean include(Entry entry) { + RowFilter containsFilter = new RowFilter() { + public boolean include(Entry entry) { for (int i = entry.getValueCount() - 1; i >= 0; i--) { if (entry.getStringValue(i).toLowerCase().contains(fragment.toLowerCase())) { return true; @@ -547,7 +547,7 @@ public class GitblitPanel extends JPanel implements CloseTabListener { return false; } }; - TableRowSorter sorter = new TableRowSorter(settingsModel); + TableRowSorter sorter = new TableRowSorter(settingsModel); sorter.setRowFilter(containsFilter); settingsTable.setRowSorter(sorter); } diff --git a/src/com/gitblit/client/RegistrationsDialog.java b/src/com/gitblit/client/RegistrationsDialog.java index ae53d5fa..71178f30 100644 --- a/src/com/gitblit/client/RegistrationsDialog.java +++ b/src/com/gitblit/client/RegistrationsDialog.java @@ -56,7 +56,7 @@ public class RegistrationsDialog extends JDialog { private JTable registrationsTable; - private RegistrationsModel model; + private RegistrationsTableModel model; public RegistrationsDialog(List registrations, RegistrationListener listener) { @@ -83,11 +83,11 @@ public class RegistrationsDialog extends JDialog { private void initialize() { NameRenderer nameRenderer = new NameRenderer(); - model = new RegistrationsModel(registrations); + model = new RegistrationsTableModel(registrations); registrationsTable = Utils.newTable(model); registrationsTable.setRowHeight(nameRenderer.getFont().getSize() + 8); - String id = registrationsTable.getColumnName(RegistrationsModel.Columns.Name.ordinal()); + String id = registrationsTable.getColumnName(RegistrationsTableModel.Columns.Name.ordinal()); registrationsTable.getColumn(id).setCellRenderer(nameRenderer); registrationsTable.addMouseListener(new MouseAdapter() { public void mouseClicked(MouseEvent e) { diff --git a/src/com/gitblit/client/RegistrationsModel.java b/src/com/gitblit/client/RegistrationsTableModel.java similarity index 90% rename from src/com/gitblit/client/RegistrationsModel.java rename to src/com/gitblit/client/RegistrationsTableModel.java index 8b4966ca..8c6b34ff 100644 --- a/src/com/gitblit/client/RegistrationsModel.java +++ b/src/com/gitblit/client/RegistrationsTableModel.java @@ -27,7 +27,7 @@ import javax.swing.table.AbstractTableModel; * @author James Moger * */ -public class RegistrationsModel extends AbstractTableModel { +public class RegistrationsTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; @@ -42,7 +42,7 @@ public class RegistrationsModel extends AbstractTableModel { } } - public RegistrationsModel(List list) { + public RegistrationsTableModel(List list) { this.list = list; Collections.sort(this.list); } diff --git a/src/com/gitblit/client/RepositoriesModel.java b/src/com/gitblit/client/RepositoriesTableModel.java similarity index 90% rename from src/com/gitblit/client/RepositoriesModel.java rename to src/com/gitblit/client/RepositoriesTableModel.java index c1fead91..9dd1a998 100644 --- a/src/com/gitblit/client/RepositoriesModel.java +++ b/src/com/gitblit/client/RepositoriesTableModel.java @@ -30,7 +30,7 @@ import com.gitblit.models.RepositoryModel; * @author James Moger * */ -public class RepositoriesModel extends AbstractTableModel { +public class RepositoriesTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; @@ -45,11 +45,11 @@ public class RepositoriesModel extends AbstractTableModel { } } - public RepositoriesModel() { + public RepositoriesTableModel() { this(new ArrayList()); } - public RepositoriesModel(List repositories) { + public RepositoriesTableModel(List repositories) { this.list = repositories; Collections.sort(this.list); } diff --git a/src/com/gitblit/client/SettingsModel.java b/src/com/gitblit/client/SettingsTableModel.java similarity index 84% rename from src/com/gitblit/client/SettingsModel.java rename to src/com/gitblit/client/SettingsTableModel.java index af3c1b60..e6d23135 100644 --- a/src/com/gitblit/client/SettingsModel.java +++ b/src/com/gitblit/client/SettingsTableModel.java @@ -18,10 +18,10 @@ package com.gitblit.client; import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.Map; import javax.swing.table.AbstractTableModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.SettingModel; /** @@ -30,11 +30,11 @@ import com.gitblit.models.SettingModel; * @author James Moger * */ -public class SettingsModel extends AbstractTableModel { +public class SettingsTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; - Map settings; + ServerSettings settings; List keys; @@ -47,20 +47,20 @@ public class SettingsModel extends AbstractTableModel { } } - public SettingsModel() { + public SettingsTableModel() { this(null); } - public SettingsModel(Map settings) { + public SettingsTableModel(ServerSettings settings) { setSettings(settings); } - public void setSettings(Map settings) { + public void setSettings(ServerSettings settings) { this.settings = settings; if (settings == null) { keys = new ArrayList(); } else { - keys = new ArrayList(settings.keySet()); + keys = new ArrayList(settings.getKeys()); Collections.sort(keys); } } diff --git a/src/com/gitblit/client/UsersModel.java b/src/com/gitblit/client/UsersTableModel.java similarity index 89% rename from src/com/gitblit/client/UsersModel.java rename to src/com/gitblit/client/UsersTableModel.java index 2b3c6443..57536adc 100644 --- a/src/com/gitblit/client/UsersModel.java +++ b/src/com/gitblit/client/UsersTableModel.java @@ -29,7 +29,7 @@ import com.gitblit.models.UserModel; * @author James Moger * */ -public class UsersModel extends AbstractTableModel { +public class UsersTableModel extends AbstractTableModel { private static final long serialVersionUID = 1L; @@ -44,11 +44,11 @@ public class UsersModel extends AbstractTableModel { } } - public UsersModel() { + public UsersTableModel() { this(new ArrayList()); } - public UsersModel(List users) { + public UsersTableModel(List users) { this.list = users; Collections.sort(this.list); } diff --git a/src/com/gitblit/models/ServerSettings.java b/src/com/gitblit/models/ServerSettings.java new file mode 100644 index 00000000..47148d32 --- /dev/null +++ b/src/com/gitblit/models/ServerSettings.java @@ -0,0 +1,63 @@ +/* + * Copyright 2011 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.models; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.TreeMap; + +import com.gitblit.IStoredSettings; + +/** + * Server settings represents the settings of the Gitblit server including all + * setting metadata such as name, current value, default value, description, and + * directives. It is a model class for serialization and presentation, but not + * for persistence. + * + * @author James Moger + */ +public class ServerSettings implements Serializable { + + private final Map settings; + + private static final long serialVersionUID = 1L; + + public ServerSettings() { + settings = new TreeMap(); + } + + public List getKeys() { + return new ArrayList(settings.keySet()); + } + + public void add(SettingModel setting) { + settings.put(setting.name, setting); + } + + public SettingModel get(String key) { + return settings.get(key); + } + + public void updateCurrentValues(IStoredSettings storedSettings) { + for (String key : storedSettings.getAllKeys(null)) { + if (settings.containsKey(key)) { + settings.get(key).currentValue = storedSettings.getString(key, ""); + } + } + } +} diff --git a/src/com/gitblit/models/ServerStatus.java b/src/com/gitblit/models/ServerStatus.java index b1dc52dd..8dfc0fbc 100644 --- a/src/com/gitblit/models/ServerStatus.java +++ b/src/com/gitblit/models/ServerStatus.java @@ -17,12 +17,12 @@ package com.gitblit.models; import java.io.Serializable; import java.util.Date; -import java.util.HashMap; import java.util.Map; +import java.util.TreeMap; /** * ServerStatus encapsulates runtime status information about the server - * including the system environment. + * including some information about the system environment. * * @author James Moger * @@ -33,10 +33,10 @@ public class ServerStatus implements Serializable { public final Date bootDate; + public final Map systemProperties; + public final long heapSize; - public final Map systemProperties; - public volatile long heapAllocated; public volatile long heapFree; @@ -46,7 +46,7 @@ public class ServerStatus implements Serializable { heapSize = Runtime.getRuntime().maxMemory(); - systemProperties = new HashMap(); + systemProperties = new TreeMap(); put("file.encoding"); put("java.home"); put("java.io.tmpdir"); diff --git a/src/com/gitblit/utils/RpcUtils.java b/src/com/gitblit/utils/RpcUtils.java index 440dabdb..2d409a0a 100644 --- a/src/com/gitblit/utils/RpcUtils.java +++ b/src/com/gitblit/utils/RpcUtils.java @@ -29,7 +29,7 @@ import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; import com.gitblit.models.RepositoryModel; import com.gitblit.models.ServerStatus; -import com.gitblit.models.SettingModel; +import com.gitblit.models.ServerSettings; import com.gitblit.models.UserModel; import com.google.gson.reflect.TypeToken; @@ -59,9 +59,6 @@ public class RpcUtils { private static final Type SETS_TYPE = new TypeToken>() { }.getType(); - private static final Type SETTINGS_TYPE = new TypeToken>() { - }.getType(); - /** * * @param remoteURL @@ -341,14 +338,13 @@ public class RpcUtils { * @param serverUrl * @param account * @param password - * @return an Map object + * @return an Settings object * @throws IOException */ - public static Map getSettings(String serverUrl, String account, - char[] password) throws IOException { + public static ServerSettings getSettings(String serverUrl, String account, char[] password) + throws IOException { String url = asLink(serverUrl, RpcRequest.LIST_SETTINGS); - Map settings = JsonUtils.retrieveJson(url, SETTINGS_TYPE, account, - password); + ServerSettings settings = JsonUtils.retrieveJson(url, ServerSettings.class, account, password); return settings; } @@ -363,7 +359,7 @@ public class RpcUtils { */ public static ServerStatus getStatus(String serverUrl, String account, char[] password) throws IOException { - String url = asLink(serverUrl, RpcRequest.LIST_SERVER_STATUS); + String url = asLink(serverUrl, RpcRequest.LIST_STATUS); ServerStatus status = JsonUtils.retrieveJson(url, ServerStatus.class, account, password); return status; } diff --git a/tests/com/gitblit/tests/RpcTests.java b/tests/com/gitblit/tests/RpcTests.java index 3c2f61f9..11a340a9 100644 --- a/tests/com/gitblit/tests/RpcTests.java +++ b/tests/com/gitblit/tests/RpcTests.java @@ -27,8 +27,8 @@ import com.gitblit.models.FederationModel; import com.gitblit.models.FederationProposal; import com.gitblit.models.FederationSet; 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; import com.gitblit.utils.RpcUtils; @@ -207,7 +207,7 @@ public class RpcTests extends TestCase { } public void testSettings() throws Exception { - Map settings = RpcUtils.getSettings(url, account, password.toCharArray()); + ServerSettings settings = RpcUtils.getSettings(url, account, password.toCharArray()); assertTrue("No settings were retrieved!", settings != null); } -- 2.39.5