From 5a57bbb18e1c795178bf2dbb979a756f0b262a57 Mon Sep 17 00:00:00 2001 From: Sebastian Sdorra Date: Sat, 21 May 2011 11:26:22 +0200 Subject: [PATCH] added create-group subcommand --- .../scm/cli/cmd/CreateGroupSubCommand.java | 207 ++++++++++++++++++ .../services/sonia.scm.cli.cmd.SubCommand | 1 + .../resources/sonia/resources/get-group.ftl | 2 +- .../resources/sonia/resources/i18n.properties | 7 +- .../resources/sonia/resources/list-groups.ftl | 3 +- 5 files changed, 217 insertions(+), 3 deletions(-) create mode 100644 scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/cmd/CreateGroupSubCommand.java diff --git a/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/cmd/CreateGroupSubCommand.java b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/cmd/CreateGroupSubCommand.java new file mode 100644 index 0000000000..419f8f2228 --- /dev/null +++ b/scm-clients/scm-cli-client/src/main/java/sonia/scm/cli/cmd/CreateGroupSubCommand.java @@ -0,0 +1,207 @@ +/** + * Copyright (c) 2010, Sebastian Sdorra + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright notice, + * this list of conditions and the following disclaimer in the documentation + * and/or other materials provided with the distribution. + * 3. Neither the name of SCM-Manager; nor the names of its + * contributors may be used to endorse or promote products derived from this + * software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + * http://bitbucket.org/sdorra/scm-manager + * + */ + + + +package sonia.scm.cli.cmd; + +//~--- non-JDK imports -------------------------------------------------------- + +import org.kohsuke.args4j.Option; + +import sonia.scm.client.ScmClientSession; +import sonia.scm.group.Group; + +//~--- JDK imports ------------------------------------------------------------ + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +/** + * + * @author Sebastian Sdorra + */ +@Command("create-group") +public class CreateGroupSubCommand extends TemplateSubCommand +{ + + /** + * Method description + * + * + * @return + */ + public String getDescription() + { + return description; + } + + /** + * Method description + * + * + * @return + */ + public List getMembers() + { + return members; + } + + /** + * Method description + * + * + * @return + */ + public String getName() + { + return name; + } + + /** + * Method description + * + * + * @return + */ + public String getType() + { + return type; + } + + //~--- set methods ---------------------------------------------------------- + + /** + * Method description + * + * + * @param description + */ + public void setDescription(String description) + { + this.description = description; + } + + /** + * Method description + * + * + * @param members + */ + public void setMembers(List members) + { + this.members = members; + } + + /** + * Method description + * + * + * @param name + */ + public void setName(String name) + { + this.name = name; + } + + /** + * Method description + * + * + * @param type + */ + public void setType(String type) + { + this.type = type; + } + + //~--- methods -------------------------------------------------------------- + + /** + * Method description + * + */ + @Override + protected void run() + { + Group group = new Group(); + + group.setName(name); + group.setDescription(description); + group.setType(type); + group.setMembers(members); + + ScmClientSession session = createSession(); + + session.getGroupHandler().create(group); + + Map env = new HashMap(); + + env.put("group", group); + renderTemplate(env, GetGroupSubCommand.TEMPLATE); + } + + //~--- fields --------------------------------------------------------------- + + /** Field description */ + @Option( + name = "--description", + usage = "optionGroupDescription", + aliases = { "-d" } + ) + private String description; + + /** Field description */ + @Option( + name = "--member", + usage = "optionGroupMember", + aliases = { "-m" } + ) + private List members; + + /** Field description */ + @Option( + name = "--name", + usage = "optionGroupName", + required = true, + aliases = { "-n" } + ) + private String name; + + /** Field description */ + @Option( + name = "--type", + usage = "optionGroupType", + aliases = { "-t" } + ) + private String type = "xml"; +} diff --git a/scm-clients/scm-cli-client/src/main/resources/META-INF/services/sonia.scm.cli.cmd.SubCommand b/scm-clients/scm-cli-client/src/main/resources/META-INF/services/sonia.scm.cli.cmd.SubCommand index 5b9037d667..539acd25a7 100644 --- a/scm-clients/scm-cli-client/src/main/resources/META-INF/services/sonia.scm.cli.cmd.SubCommand +++ b/scm-clients/scm-cli-client/src/main/resources/META-INF/services/sonia.scm.cli.cmd.SubCommand @@ -52,3 +52,4 @@ sonia.scm.cli.cmd.ModifyUserSubCommand # group sonia.scm.cli.cmd.ListGroupsSubCommand sonia.scm.cli.cmd.GetGroupSubCommand +sonia.scm.cli.cmd.CreateGroupSubCommand diff --git a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/get-group.ftl b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/get-group.ftl index 6cf544dbac..0d99bdee24 100644 --- a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/get-group.ftl +++ b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/get-group.ftl @@ -1,6 +1,6 @@ Name: ${group.name} Type: ${group.type} -Description: ${group.description} +Description: ${group.description!""} Creation-Date: ${group.creationDate!""?string} Last-Modified: ${group.lastModified!""?string} Members: diff --git a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties index 39810bcfdd..c5c9b86b3a 100644 --- a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties +++ b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/i18n.properties @@ -44,7 +44,7 @@ optionRepositoryContact = Repository contact optionRepositoryDescription = Repository description optionRepositoryPublic = Repository public readable -optionPermissionGroup = Gtoup +optionPermissionGroup = Group optionPermissionName = Group or user name optionPermissionType = Permission type (READ,WRITE or OWNER) @@ -55,6 +55,11 @@ optionUserPassword = Password optionUserType = Type optionUserAdmin = Administrator +optionGroupName = Name +optionGroupDescription = Description +optionGroupType = Type +optionGroupMember = Member + repositoryNotFound = The repository is not available userNotFound = The user could not be found groupNotFoun = The group could not be found diff --git a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/list-groups.ftl b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/list-groups.ftl index adcb05277d..922333b5af 100644 --- a/scm-clients/scm-cli-client/src/main/resources/sonia/resources/list-groups.ftl +++ b/scm-clients/scm-cli-client/src/main/resources/sonia/resources/list-groups.ftl @@ -1,7 +1,7 @@ <#list groups as group> Name: ${group.name} Type: ${group.type} -Description: ${group.description} +Description: ${group.description!""} Creation-Date: ${group.creationDate!""?string} Last-Modified: ${group.lastModified!""?string} Members: @@ -10,4 +10,5 @@ Members: ${member} + \ No newline at end of file