Merge pull request #16 from jcrygier/custom_properties
Custom Defined Repository Properties (Issue #92)
1 files added
10 files modified
| | |
| | | # 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 = |
| | |
| | |
|
| | | public static final String DEFAULT_BRANCH = "default";
|
| | |
|
| | | public static String CUSTOM_FIELDS_PROP_SECTION = "gitblit";
|
| | | |
| | | public static String CUSTOM_FIELDS_PROP_SUBSECTION = "customFields";
|
| | | |
| | | public static String getGitBlitVersion() {
|
| | | return NAME + " v" + VERSION;
|
| | | }
|
| | |
| | | "gitblit", null, "mailingList")));
|
| | | model.indexedBranches = new ArrayList<String>(Arrays.asList(config.getStringList(
|
| | | "gitblit", null, "indexBranch")));
|
| | | |
| | | // Custom defined properties
|
| | | model.customFields = new HashMap<String, String>();
|
| | | 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));
|
| | | }
|
| | | }
|
| | | model.HEAD = JGitUtils.getHEADRef(r);
|
| | | model.availableRefs = JGitUtils.getAvailableHeadTargets(r);
|
| | |
| | | updateList(config, "postReceiveScript", repository.postReceiveScripts);
|
| | | updateList(config, "mailingList", repository.mailingLists);
|
| | | updateList(config, "indexBranch", repository.indexedBranches);
|
| | | |
| | | // User Defined Properties
|
| | | for (Entry<String, String> singleProperty : repository.customFields.entrySet()) {
|
| | | config.setString(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION, singleProperty.getKey(), singleProperty.getValue());
|
| | | }
|
| | |
|
| | | try {
|
| | | config.save();
|
| | |
| | | import java.text.MessageFormat;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.HashMap;
|
| | | import java.util.HashSet;
|
| | | import java.util.List;
|
| | | import java.util.Set;
|
| | |
|
| | | import javax.swing.Box;
|
| | | import javax.swing.BoxLayout;
|
| | | import javax.swing.DefaultComboBoxModel;
|
| | | import javax.swing.ImageIcon;
|
| | | import javax.swing.JButton;
|
| | |
| | | import javax.swing.JOptionPane;
|
| | | import javax.swing.JPanel;
|
| | | import javax.swing.JRootPane;
|
| | | import javax.swing.JScrollPane;
|
| | | import javax.swing.JTabbedPane;
|
| | | import javax.swing.JTextField;
|
| | | import javax.swing.KeyStroke;
|
| | | import javax.swing.ListCellRenderer;
|
| | | import javax.swing.ScrollPaneConstants;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | |
| | | private JLabel postReceiveInherited;
|
| | |
|
| | | private Set<String> repositoryNames;
|
| | | |
| | | private JPanel customFieldsPanel;
|
| | |
|
| | | public EditRepositoryDialog(int protocolVersion) {
|
| | | this(protocolVersion, new RepositoryModel());
|
| | |
| | | JPanel postReceivePanel = new JPanel(new BorderLayout(5, 5));
|
| | | postReceivePanel.add(postReceivePalette, BorderLayout.CENTER);
|
| | | postReceivePanel.add(postReceiveInherited, BorderLayout.WEST);
|
| | | |
| | | customFieldsPanel = new JPanel();
|
| | | customFieldsPanel.setLayout(new BoxLayout(customFieldsPanel, BoxLayout.Y_AXIS));
|
| | | JScrollPane customFieldsScrollPane = new JScrollPane(customFieldsPanel);
|
| | | customFieldsScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
|
| | | customFieldsScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
|
| | |
|
| | | JTabbedPane panel = new JTabbedPane(JTabbedPane.TOP);
|
| | | panel.addTab(Translation.get("gb.general"), fieldsPanel);
|
| | |
| | | }
|
| | | panel.addTab(Translation.get("gb.preReceiveScripts"), preReceivePanel);
|
| | | panel.addTab(Translation.get("gb.postReceiveScripts"), postReceivePanel);
|
| | | |
| | | panel.addTab(Translation.get("gb.customFields"), customFieldsScrollPane);
|
| | | |
| | |
|
| | | JButton createButton = new JButton(Translation.get("gb.save"));
|
| | | createButton.addActionListener(new ActionListener() {
|
| | |
| | | pack();
|
| | | nameField.requestFocus();
|
| | | }
|
| | |
|
| | | |
| | | private JPanel newFieldPanel(String label, JComponent comp) {
|
| | | return newFieldPanel(label, 150, comp);
|
| | | }
|
| | |
|
| | | private JPanel newFieldPanel(String label, int labelSize, JComponent comp) {
|
| | | JLabel fieldLabel = new JLabel(label);
|
| | | fieldLabel.setFont(fieldLabel.getFont().deriveFont(Font.BOLD));
|
| | | fieldLabel.setPreferredSize(new Dimension(150, 20));
|
| | | fieldLabel.setPreferredSize(new Dimension(labelSize, 20));
|
| | | JPanel panel = new JPanel(new FlowLayout(FlowLayout.LEFT, 10, 0));
|
| | | panel.add(fieldLabel);
|
| | | panel.add(comp);
|
| | |
| | | repository.indexedBranches = indexedBranchesPalette.getSelections();
|
| | | repository.preReceiveScripts = preReceivePalette.getSelections();
|
| | | repository.postReceiveScripts = postReceivePalette.getSelections();
|
| | | |
| | | // Custom Fields
|
| | | repository.customFields = new HashMap<String, String>();
|
| | | |
| | | for (Component aCustomFieldPanel : customFieldsPanel.getComponents()) {
|
| | | JTextField textField = (JTextField) ((JPanel)aCustomFieldPanel).getComponent(1);
|
| | | repository.customFields.put(textField.getName(), textField.getText());
|
| | | }
|
| | | |
| | | return true;
|
| | | }
|
| | |
|
| | |
| | | public List<String> getPermittedTeams() {
|
| | | return teamsPalette.getSelections();
|
| | | }
|
| | | |
| | | public void setCustomFields(RepositoryModel repository, List<String> customFields) {
|
| | | customFieldsPanel.removeAll();
|
| | | |
| | | for (String customFieldDef : customFields) {
|
| | | String[] customFieldProperty = customFieldDef.split("=");
|
| | | String fieldName = customFieldProperty[0];
|
| | | String fieldLabel = customFieldProperty[1];
|
| | | |
| | | JTextField textField = new JTextField(repository.customFields.get(fieldName), 50);
|
| | | textField.setName(fieldName);
|
| | | |
| | | customFieldsPanel.add(newFieldPanel(fieldLabel, 250, textField));
|
| | | }
|
| | | |
| | | if (customFields.size() < 14) {
|
| | | customFieldsPanel.add(Box.createVerticalGlue());
|
| | | customFieldsPanel.add(Box.createRigidArea(new Dimension(300, 300 - (customFields.size() * 22))));
|
| | | }
|
| | | }
|
| | |
|
| | | /**
|
| | | * ListCellRenderer to display descriptive text about the access
|
| | |
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.RpcRequest;
|
| | | import com.gitblit.Keys;
|
| | | import com.gitblit.models.FeedModel;
|
| | | import com.gitblit.models.RepositoryModel;
|
| | | import com.gitblit.utils.StringUtils;
|
| | |
| | | gitblit.getPreReceiveScriptsInherited(repository), repository.preReceiveScripts);
|
| | | dialog.setPostReceiveScripts(gitblit.getPostReceiveScriptsUnused(repository),
|
| | | gitblit.getPostReceiveScriptsInherited(repository), repository.postReceiveScripts);
|
| | | dialog.setCustomFields(repository, gitblit.getSettings().get(Keys.repository.customFields).getStrings());
|
| | | dialog.setVisible(true);
|
| | | final RepositoryModel revisedRepository = dialog.getRepository();
|
| | | final List<String> permittedUsers = dialog.getPermittedUsers();
|
| | |
| | | import java.util.ArrayList;
|
| | | import java.util.Date;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | |
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | |
| | | public List<String> preReceiveScripts;
|
| | | public List<String> postReceiveScripts;
|
| | | public List<String> mailingLists;
|
| | | public Map<String, String> customFields;
|
| | | private String displayName;
|
| | |
|
| | | public RepositoryModel() {
|
| | |
| | | gb.preReceiveScripts = pre-receive scripts
|
| | | gb.postReceiveScripts = post-receive scripts
|
| | | gb.hookScripts = hook scripts
|
| | | gb.customFields = custom fields
|
| | | gb.customFieldsDescription = custom fields available to groovy hooks
|
| | | gb.accessPermissions = access permissions
|
| | | gb.filters = filters
|
| | | gb.generalDescription = common settings
|
| | |
| | | <tr><td colspan="2"><h3><wicket:message key="gb.hookScripts"></wicket:message> <small><wicket:message key="gb.hookScriptsDescription"></wicket:message></small></h3></td></tr>
|
| | | <tr><th style="vertical-align: top;"><wicket:message key="gb.preReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPreReceive"></span></th><td style="padding:2px;"><span wicket:id="preReceiveScripts"></span></td></tr>
|
| | | <tr><th style="vertical-align: top;"><wicket:message key="gb.postReceiveScripts"></wicket:message><p></p><span wicket:id="inheritedPostReceive"></span></th><td style="padding:2px;"><span wicket:id="postReceiveScripts"></span></td></tr>
|
| | | <tr><td colspan='2'><div class="form-actions"><input class="btn btn-primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="16" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="17" /></div></td></tr>
|
| | | <div wicket:id="customFiledsSection">
|
| | | <tr><td colspan="2"><h3><wicket:message key="gb.customFields"></wicket:message> <small><wicket:message key="gb.customFieldsDescription"></wicket:message></small></h3></td></tr>
|
| | | <tr wicket:id="customFieldsListView"><th style="vertical-align: top;"><span wicket:id="customFieldLabel"></span></th><td class="edit"><input class="span8" type="text" wicket:id="customFieldValue" size="30" tabindex="16" /></td></tr>
|
| | | </div>
|
| | | <tr><td colspan='2'><div class="form-actions"><input class="btn btn-primary" type="submit" value="Save" wicket:message="value:gb.save" wicket:id="save" tabindex="17" /> <input class="btn" type="submit" value="Cancel" wicket:message="value:gb.cancel" wicket:id="cancel" tabindex="18" /></div></td></tr>
|
| | | </tbody>
|
| | | </table>
|
| | | </form>
|
| | |
| | | package com.gitblit.wicket.pages;
|
| | |
|
| | | import java.text.MessageFormat;
|
| | | import java.util.AbstractMap;
|
| | | import java.util.ArrayList;
|
| | | import java.util.Arrays;
|
| | | import java.util.Collections;
|
| | |
| | | import java.util.Iterator;
|
| | | import java.util.List;
|
| | | import java.util.Map;
|
| | | import java.util.Map.Entry;
|
| | | import java.util.Set;
|
| | |
|
| | | import org.apache.wicket.PageParameters;
|
| | | import org.apache.wicket.behavior.SimpleAttributeModifier;
|
| | | import org.apache.wicket.extensions.markup.html.form.palette.Palette;
|
| | | import org.apache.wicket.markup.html.WebMarkupContainer;
|
| | | import org.apache.wicket.markup.html.basic.Label;
|
| | | import org.apache.wicket.markup.html.form.Button;
|
| | | import org.apache.wicket.markup.html.form.CheckBox;
|
| | | import org.apache.wicket.markup.html.form.DropDownChoice;
|
| | | import org.apache.wicket.markup.html.form.Form;
|
| | | import org.apache.wicket.markup.html.form.IChoiceRenderer;
|
| | | import org.apache.wicket.markup.html.form.TextField;
|
| | | import org.apache.wicket.markup.html.list.ListItem;
|
| | | import org.apache.wicket.markup.html.list.ListItemModel;
|
| | | import org.apache.wicket.markup.html.list.ListView;
|
| | | import org.apache.wicket.model.CompoundPropertyModel;
|
| | | import org.apache.wicket.model.IModel;
|
| | | import org.apache.wicket.model.Model;
|
| | | import org.apache.wicket.model.util.CollectionModel;
|
| | | import org.apache.wicket.model.util.ListModel;
|
| | |
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.Constants.AccessRestrictionType;
|
| | | import com.gitblit.Constants.FederationStrategy;
|
| | | import com.gitblit.Constants;
|
| | | import com.gitblit.GitBlit;
|
| | | import com.gitblit.GitBlitException;
|
| | | import com.gitblit.Keys;
|
| | |
| | | new ListModel<String>(postReceiveScripts), new CollectionModel<String>(GitBlit
|
| | | .self().getPostReceiveScriptsUnused(repositoryModel)),
|
| | | new StringChoiceRenderer(), 12, true);
|
| | | |
| | | // Dynamic Custom Defined Properties Properties
|
| | | final List<Entry<String, String>> definedProperties = new ArrayList<Entry<String, String>>();
|
| | | List<String> customFields = GitBlit.getStrings(Keys.repository.customFields);
|
| | | for (String customFieldDef : customFields) {
|
| | | String[] customFieldProperty = customFieldDef.split("=");
|
| | | definedProperties.add(new AbstractMap.SimpleEntry<String, String>(customFieldProperty[0], customFieldProperty[1]));
|
| | | }
|
| | | |
| | | final ListView<Entry<String, String>> customFieldsListView = new ListView<Entry<String, String>>("customFieldsListView", definedProperties) {
|
| | | @Override
|
| | | protected void populateItem(ListItem<Entry<String, String>> item) {
|
| | | String value = repositoryModel.customFields.get(item.getModelObject().getKey());
|
| | | |
| | | item.add(new Label(item.getModelObject().getKey(), item.getModelObject().getValue())); // Used to get the key later
|
| | | item.add(new Label("customFieldLabel", item.getModelObject().getValue()));
|
| | | item.add(new TextField<String>("customFieldValue", new Model<String>(value)));
|
| | | }
|
| | | };
|
| | | customFieldsListView.setReuseItems(true);
|
| | |
|
| | | CompoundPropertyModel<RepositoryModel> model = new CompoundPropertyModel<RepositoryModel>(
|
| | | repositoryModel);
|
| | |
| | | postReceiveScripts.add(post.next());
|
| | | }
|
| | | repositoryModel.postReceiveScripts = postReceiveScripts;
|
| | |
|
| | | |
| | | // Loop over each of the user defined properties
|
| | | for (int i = 0; i < customFieldsListView.size(); i++) {
|
| | | ListItem<ListItemModel<String>> item = (ListItem<ListItemModel<String>>) customFieldsListView.get(i);
|
| | | String key = item.get(0).getId(); // Item 0 is our 'fake' label
|
| | | String value = ((TextField<String>)item.get(2)).getValue(); // Item 2 is out text box
|
| | | |
| | | repositoryModel.customFields.put(key, value);
|
| | | }
|
| | | |
| | | // save the repository
|
| | | GitBlit.self().updateRepositoryModel(oldName, repositoryModel, isCreate);
|
| | |
|
| | |
| | | form.add(postReceivePalette);
|
| | | form.add(new BulletListPanel("inheritedPostReceive", "inherited", GitBlit.self()
|
| | | .getPostReceiveScriptsInherited(repositoryModel)));
|
| | | |
| | | WebMarkupContainer customFiledsSection = new WebMarkupContainer("customFiledsSection") {
|
| | | public boolean isVisible() {
|
| | | return GitBlit.getString(Keys.repository.customFields, "").isEmpty() == false;
|
| | | };
|
| | | };
|
| | | customFiledsSection.add(customFieldsListView);
|
| | | form.add(customFiledsSection);
|
| | |
|
| | | form.add(new Button("save"));
|
| | | Button cancel = new Button("cancel") {
|
| | |
| | | MarkdownUtilsTest.class, JGitUtilsTest.class, SyndicationUtilsTest.class,
|
| | | DiffUtilsTest.class, MetricUtilsTest.class, TicgitUtilsTest.class,
|
| | | GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class,
|
| | | GroovyScriptTest.class, LuceneExecutorTest.class, IssuesTest.class })
|
| | | GroovyScriptTest.class, LuceneExecutorTest.class, IssuesTest.class, RepositoryModelTest.class })
|
| | | public class GitBlitSuite {
|
| | |
|
| | | public static final File REPOSITORIES = new File("git");
|
New file |
| | |
| | | package com.gitblit.tests; |
| | | |
| | | import static org.junit.Assert.assertEquals; |
| | | |
| | | import org.eclipse.jgit.lib.Repository; |
| | | import org.eclipse.jgit.lib.StoredConfig; |
| | | import org.junit.After; |
| | | import org.junit.AfterClass; |
| | | 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; |
| | | |
| | | 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 |
| | | public void initializeConfiguration() throws Exception{ |
| | | 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.save(); |
| | | } |
| | | |
| | | @After |
| | | public void teardownConfiguration() throws Exception { |
| | | Repository r = GitBlitSuite.getHelloworldRepository(); |
| | | StoredConfig config = JGitUtils.readConfig(r); |
| | | |
| | | config.unsetSection(Constants.CUSTOM_FIELDS_PROP_SECTION, Constants.CUSTOM_FIELDS_PROP_SUBSECTION); |
| | | config.save(); |
| | | } |
| | | |
| | | @Test |
| | | public void testGetCustomProperty() throws Exception { |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel( |
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
| | | |
| | | assertEquals("\\d", model.customFields.get("commitMessageRegEx")); |
| | | assertEquals("Hello", model.customFields.get("anotherProperty")); |
| | | } |
| | | |
| | | @Test |
| | | public void testSetCustomProperty() throws Exception { |
| | | RepositoryModel model = GitBlit.self().getRepositoryModel( |
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
| | | |
| | | assertEquals("\\d", model.customFields.get("commitMessageRegEx")); |
| | | assertEquals("Hello", model.customFields.get("anotherProperty")); |
| | | |
| | | assertEquals("Hello", model.customFields.put("anotherProperty", "GoodBye")); |
| | | GitBlit.self().updateRepositoryModel(model.name, model, false); |
| | | |
| | | model = GitBlit.self().getRepositoryModel( |
| | | GitBlitSuite.getHelloworldRepository().getDirectory().getName()); |
| | | |
| | | assertEquals("\\d", model.customFields.get("commitMessageRegEx")); |
| | | assertEquals("GoodBye", model.customFields.get("anotherProperty")); |
| | | } |
| | | |
| | | } |