Return-Path: Delivered-To: apmail-geronimo-scm-archive@www.apache.org Received: (qmail 28809 invoked from network); 4 Dec 2007 10:47:07 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Dec 2007 10:47:07 -0000 Received: (qmail 71540 invoked by uid 500); 4 Dec 2007 10:46:55 -0000 Delivered-To: apmail-geronimo-scm-archive@geronimo.apache.org Received: (qmail 71527 invoked by uid 500); 4 Dec 2007 10:46:55 -0000 Mailing-List: contact scm-help@geronimo.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: dev@geronimo.apache.org List-Id: Delivered-To: mailing list scm@geronimo.apache.org Received: (qmail 71516 invoked by uid 99); 4 Dec 2007 10:46:55 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2007 02:46:55 -0800 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Dec 2007 10:46:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A71751A9832; Tue, 4 Dec 2007 02:46:31 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r600872 - in /geronimo/server/trunk: ./ assemblies/geronimo-boilerplate-minimal/ assemblies/geronimo-boilerplate-minimal/src/main/assembly/ assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/ framework/modules/geronimo-commands/ ... Date: Tue, 04 Dec 2007 10:46:29 -0000 To: scm@geronimo.apache.org From: gdamour@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20071204104631.A71751A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: gdamour Date: Tue Dec 4 02:46:27 2007 New Revision: 600872 URL: http://svn.apache.org/viewvc?rev=600872&view=rev Log: Add a couple of gshell commands to simplify the remote control of servers. The commands being added are: * alias: used to alias a commond along with some options and arguments. etc/layout.xml provides a first aliasing mechanism: a hierarchical name is mapped to a command. alias suplements this first aliasing mechanism with the ability to alias a command along with its typical options and arguments. * unalias: to remove an alias * execute-alias: to execute an alias * remote/rsh to start an rsh client * remote/rsh-server to start an rsh-server * remote-control/server-control to control a server Samples for the aliasing commands: // create the alias 'st' for the quoted command > alias st 'geronimo/start-server -G server.name=yellow -D property=value' // execute the alias 'st'. This executes the command in quote above > excute-alias st // display defined aliases > alias // remove the alias 'st' > unalias st Samples for the remote server control commands: // start an rsh-server: > remote/rsh-server tcp://localhost:9999 // remote 'start' the server 'defaultServer' > remote-control/server-control start defaultServer // remote 'stop' the server 'defaultServer' > remote-control/server-control stop defaultServer All the commands are implemented in Groovy. XML manipulations are done via XmlSlurpers. Aliases are stored in a configuration file located by default in etc/aliases.xml Server configurations, used by the remote control command, are stored in a configuration file located by default in etc/server-configuration.xml New JARs are being added to lib/gshell for the support of the rsh bits. Added: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/aliases.xml geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/server-configuration.xml geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AbstractAliasCommand.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AliasCommand.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ExecuteAliasCommand.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/RemoteServerControlCommand.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/UnaliasCommand.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/test/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/AliasCommandTest.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/ExecuteAliasCommandTest.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/GroovyTestSupport.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/RemoteServerControlCommandTest.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/UnaliasCommandTest.groovy geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/aliases.xml geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/server-configuration.xml Modified: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/pom.xml geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/assembly/boilerplate.xml geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml geronimo/server/trunk/framework/modules/geronimo-commands/pom.xml geronimo/server/trunk/pom.xml Modified: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/pom.xml?rev=600872&r1=600871&r2=600872&view=diff ============================================================================== --- geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/pom.xml (original) +++ geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/pom.xml Tue Dec 4 02:46:27 2007 @@ -65,6 +65,36 @@ + org.apache.geronimo.gshell + gshell-whisper + + + + org.apache.geronimo.gshell.remote + gshell-remote-client + + + + org.apache.geronimo.gshell.remote + gshell-remote-common + + + + org.apache.geronimo.gshell.remote + gshell-remote-server + + + + org.apache.mina + mina-core + + + + org.apache.mina + mina-filter-ssl + + + org.slf4j slf4j-log4j12 Modified: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/assembly/boilerplate.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/assembly/boilerplate.xml?rev=600872&r1=600871&r2=600872&view=diff ============================================================================== --- geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/assembly/boilerplate.xml (original) +++ geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/assembly/boilerplate.xml Tue Dec 4 02:46:27 2007 @@ -36,6 +36,15 @@ org.apache.geronimo.modules:geronimo-commands org.apache.geronimo.gshell:gshell-embeddable org.apache.geronimo.gshell:gshell-cli + + + org.apache.geronimo.gshell:gshell-whisper + org.apache.geronimo.gshell.remote:gshell-remote-client + org.apache.geronimo.gshell.remote:gshell-remote-common + org.apache.geronimo.gshell.remote:gshell-remote-server + org.apache.mina:mina-core + org.apache.mina:mina-filter-ssl + org.codehaus.groovy:groovy-all org.apache.ant:ant org.apache.ant:ant-launcher Added: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/aliases.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/aliases.xml?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/aliases.xml (added) +++ geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/aliases.xml Tue Dec 4 02:46:27 2007 @@ -0,0 +1,30 @@ + + + + + + + + geronimo/start-server -b + + + geronimo/stop-server + + \ No newline at end of file Modified: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml?rev=600872&r1=600871&r2=600872&view=diff ============================================================================== --- geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml (original) +++ geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/layout.xml Tue Dec 4 02:46:27 2007 @@ -80,6 +80,21 @@ gshell-builtins:unset + + alias + geronimo-commands:alias + + + + unalias + geronimo-commands:unalias + + + + execute-alias + geronimo-commands:execute-alias + + @@ -94,6 +109,30 @@ stop-server geronimo-commands:stop-server + + + + + + remote + + + rsh + gshell-remote:rsh + + + rsh-server + gshell-remote:rsh-server + + + + + + remote-control + + + server-control + geronimo-commands:remote-server-control Added: geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/server-configuration.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/server-configuration.xml?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/server-configuration.xml (added) +++ geronimo/server/trunk/assemblies/geronimo-boilerplate-minimal/src/main/underlay/etc/server-configuration.xml Tue Dec 4 02:46:27 2007 @@ -0,0 +1,40 @@ + + + + + + + + + + remote/rsh -u NOT_USED -p NOT_USED tcp://localhost:9999 + + + + + + + + execute-alias start_DEFAULT_SERVER + execute-alias stop_DEFAULT_SERVER + + + + Modified: geronimo/server/trunk/framework/modules/geronimo-commands/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/pom.xml?rev=600872&r1=600871&r2=600872&view=diff ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/pom.xml (original) +++ geronimo/server/trunk/framework/modules/geronimo-commands/pom.xml Tue Dec 4 02:46:27 2007 @@ -49,7 +49,13 @@ org.slf4j slf4j-api - + + + org.slf4j + slf4j-simple + test + + org.apache.geronimo.gshell gshell-command-api @@ -133,6 +139,7 @@ compile + testCompile Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AbstractAliasCommand.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AbstractAliasCommand.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AbstractAliasCommand.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AbstractAliasCommand.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,76 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands + +import groovy.xml.StreamingMarkupBuilder + +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option +import org.apache.geronimo.gshell.command.annotation.CommandComponent +import org.apache.geronimo.gshell.command.annotation.Requirement +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.CommandSupport +import org.apache.geronimo.gshell.command.IO + + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +abstract class AbstractAliasCommand extends CommandSupport { + + @Option(name='-c', aliases=['--alias-configuration'], description='Alias configuration file') + String aliasFileName = 'etc/aliases.xml' + + @Argument(index=0, description="alias") + String aliasName + + def buildAvailableAliases = { aliases -> + def availables = '\nAvailable aliases:\n' + aliases.alias.list().sort{ it.@id.text() }.each { + availables += " ${it.@id.text()} '${it.'*'.text()}'\n" + } + availables + } + + def checkAliasFile = { + def aliasFile = new File(aliasFileName) + if (!aliasFile.exists()) { + throw new IllegalStateException("Alias file ${aliasFile.absolutePath} does not exist") + } + aliasFile + } + + def serializeToXML = { aliases -> + def outputBuilder = new StreamingMarkupBuilder() + outputBuilder.bind { mkp.yield aliases } + } + + def createNewAliasFile = { aliasFile, aliasFileName, xml -> + aliasFile.renameTo(new File(aliasFileName + ".bak")) + + aliasFile = new File(aliasFileName) + aliasFile.createNewFile() + aliasFile.withPrintWriter { + it.write(xml) + } + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AliasCommand.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AliasCommand.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AliasCommand.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/AliasCommand.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,79 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands + +import groovy.xml.StreamingMarkupBuilder + +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option +import org.apache.geronimo.gshell.command.annotation.CommandComponent +import org.apache.geronimo.gshell.command.annotation.Requirement +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.CommandSupport +import org.apache.geronimo.gshell.command.IO + + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +@CommandComponent(id='geronimo-commands:alias', description="Create an alias") +class AliasCommand extends AbstractAliasCommand { + + @Argument(index=1, description="Command") + String command + + protected Object doExecute() throws Exception { + def aliasFile = checkAliasFile() + + def xml + aliasFile.withInputStream { + def aliases = new XmlSlurper().parse(it) + + if (!aliasName) { + io.out.println(buildAvailableAliases(aliases)) + return + } + + if (!aliases.alias.find { it.@id.text().equals(aliasName) }.isEmpty()) { + throw new IllegalArgumentException("${aliasName} is already defined") + } else if (!command) { + throw new IllegalArgumentException("command is required") + } + + aliases.appendNode { + alias(id: aliasName) { + cli(command) + } + } + + xml = serializeToXML(aliases) + } + + if (!xml) { + return false + } + + createNewAliasFile(aliasFile, aliasFileName, xml) + + true + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ExecuteAliasCommand.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ExecuteAliasCommand.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ExecuteAliasCommand.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/ExecuteAliasCommand.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands + +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option +import org.apache.geronimo.gshell.command.annotation.CommandComponent +import org.apache.geronimo.gshell.command.annotation.Requirement +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.CommandSupport +import org.apache.geronimo.gshell.command.IO + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +@CommandComponent(id='geronimo-commands:execute-alias', description="Execute an alias") +class ExecuteAliasCommand extends AbstractAliasCommand { + + @Requirement + CommandExecutor executor + + protected Object doExecute() throws Exception { + def aliasFile = checkAliasFile() + + def result + aliasFile.withInputStream({ + def aliases = new XmlSlurper().parse(it) + + def alias = aliases.alias.find { it.@id.text().equals(aliasName) } + if (alias.isEmpty()) { + def availables = buildAvailableAliases(aliases) + throw new IllegalArgumentException("${aliasName} does not exist.${availables}") + } + + def cli = alias.cli.text() + if ('' == cli) { + throw new UnsupportedOperationException("alias.cli is not defined by alias ${aliasName}") + } + + result = executor.execute(cli) + }) + + result + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/RemoteServerControlCommand.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/RemoteServerControlCommand.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/RemoteServerControlCommand.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/RemoteServerControlCommand.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands + +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option +import org.apache.geronimo.gshell.command.annotation.CommandComponent +import org.apache.geronimo.gshell.command.annotation.Requirement +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.CommandSupport +import org.apache.geronimo.gshell.command.IO + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +@CommandComponent(id='geronimo-commands:remote-server-control', description="Remote server control") +class RemoteServerControlCommand extends CommandSupport { + + @Requirement + CommandExecutor executor + + @Option(name='-c', aliases=['--server-configuration'], description='Server configuration file') + String configurationFileName = 'etc/server-configuration.xml' + + @Argument(metaVar="CONTROL", required=true, index=0, description="Control") + String control + + @Argument(metaVar="SERVER", required=true, index=1, description="Server") + String serverName + + protected Object doExecute() throws Exception { + def configurationFile = new File(configurationFileName) + if (!configurationFile.exists()) { + throw new IllegalStateException("File ${configurationFile.absolutePath} does not exist") + } + + def result + configurationFile.withInputStream { + result = executeRshCommand(it) + } + result + } + + protected executeRshCommand(is) { + def configuration = new XmlSlurper().parse(is) + + def retrieveByNameAttribute = { baseNode, name -> + def node = baseNode.find { it.@name.text().equals(name) } + if (node.isEmpty()) { + def availableNames = baseNode.list().sort{ it.@name.text() }.'@name'*.text() + throw new IllegalArgumentException("${name} does not exist. Available: ${availableNames}") + } + node + } + + def server = retrieveByNameAttribute(configuration.servers.server, serverName) + def host = retrieveByNameAttribute(configuration.hosts.host, server.host.@name.text()) + + def rshCmd = host.gshell.'remote-login-cmd'.text() + if ('' == rshCmd) { + throw new IllegalStateException("gshell.remote-login-cmd is not defined by host ${host.@name.text()}") + } + + def command = server.controls."${control}".text() + if ('' == command) { + def controls = server.controls.'*'.list().sort{ it.name() }*.name() + throw new IllegalStateException("server.controls.${control} is not defined by server " + + "${server.@name.text()}.\nAvailable controls: ${controls}") + } + + executor.execute("${rshCmd} ${command}") + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/UnaliasCommand.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/UnaliasCommand.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/UnaliasCommand.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/main/groovy/org/apache/geronimo/commands/UnaliasCommand.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,70 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands + +import groovy.xml.StreamingMarkupBuilder + +import org.apache.geronimo.gshell.clp.Argument; +import org.apache.geronimo.gshell.clp.Option +import org.apache.geronimo.gshell.command.annotation.CommandComponent +import org.apache.geronimo.gshell.command.annotation.Requirement +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.CommandSupport +import org.apache.geronimo.gshell.command.IO + + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +@CommandComponent(id='geronimo-commands:unalias', description="Remove an alias") +class UnaliasCommand extends AbstractAliasCommand { + + protected Object doExecute() throws Exception { + def aliasFile = checkAliasFile() + + if (!aliasName) { + throw new IllegalArgumentException("an alias must be specified") + } + + def xml + aliasFile.withInputStream { + def aliases = new XmlSlurper().parse(it) + + def alias = aliases.alias.find { it.@id.text().equals(aliasName) } + if ('' == alias.text()) { + return + } + + alias.replaceNode {} + + xml = serializeToXML(aliases) + } + + if (!xml) { + return false + } + + createNewAliasFile(aliasFile, aliasFileName, xml) + + true + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/AliasCommandTest.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/AliasCommandTest.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/AliasCommandTest.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/AliasCommandTest.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,86 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands; + +import org.apache.geronimo.gshell.command.IO + +import org.apache.geronimo.testsupport.TestSupport + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +class AliasCommandTest extends GroovyTestCase { + + def command + + protected void setUp() { + def testSupport = new GroovyTestSupport() + + File baseFile = testSupport.resolveFile('src/test/resources/etc/aliases.xml') + def lines = baseFile.readLines() + + def workingFile = testSupport.resolveFile('build/etc/aliases.xml') + workingFile.parentFile.mkdirs() + workingFile.createNewFile() + workingFile.withPrintWriter { pw -> + lines.each { pw.println(it) } + } + + command = new AliasCommand([io: new IO(), aliasFileName: workingFile.absolutePath]) + } + + void testAliasFileDoesNotExistThrowsISE() { + shouldFail(IllegalStateException.class) { + command.aliasFileName = 'doesNotExist' + command.doExecute() + } + } + + void testNoAliasArgumentDisplaysAvailableAliases() { + command.doExecute() + } + + void testAliasWithoutCommandThrowsIAE() { + shouldFail(IllegalArgumentException.class) { + command.aliasName = 'anNewAlias' + command.doExecute() + } + } + + void testAliasAnExistingAliasThrowsIAE() { + shouldFail(IllegalArgumentException.class) { + command.aliasName = 'start_DEFAULT_SERVER' + command.command = 'test' + command.doExecute() + } + } + + void testAlias() { + command.aliasName = 'start_DEFAULT_SERVER_TWO' + command.command = 'test' + command.doExecute() + + shouldFail(IllegalArgumentException.class) { + command.doExecute() + } + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/ExecuteAliasCommandTest.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/ExecuteAliasCommandTest.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/ExecuteAliasCommandTest.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/ExecuteAliasCommandTest.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,73 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands; + +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.IO + +import org.apache.geronimo.testsupport.TestSupport + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +class ExecuteAliasCommandTest extends GroovyTestCase { + + def command + def executedCommand + + protected void setUp() { + def testSupport = new GroovyTestSupport() + + File aliasFile = testSupport.resolveFile('src/test/resources/etc/aliases.xml') + + command = new ExecuteAliasCommand([io: new IO(), aliasFileName: aliasFile.absolutePath]) + command.executor = { executedCommand = it } as CommandExecutor + } + + void testAliasFileDoesNotExistThrowsISE() { + shouldFail(IllegalStateException.class) { + command.aliasFileName = 'doesNotExist' + command.doExecute() + } + } + + void testExecuteUndefinedAliasThrowsIAE() { + shouldFail(IllegalArgumentException.class) { + command.aliasName = 'undefined' + command.doExecute() + } + } + + void testExecuteAliasWithoutCLIThrowsUOE() { + shouldFail(UnsupportedOperationException.class) { + command.aliasName = 'alias_without_cli' + command.doExecute() + } + } + + void testExecuteAlias() { + command.aliasName = 'start_DEFAULT_SERVER' + command.doExecute() + + assert 'start-server -d' == executedCommand + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/GroovyTestSupport.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/GroovyTestSupport.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/GroovyTestSupport.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/GroovyTestSupport.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands; + +import org.apache.geronimo.testsupport.TestSupport + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +class GroovyTestSupport extends TestSupport { +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/RemoteServerControlCommandTest.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/RemoteServerControlCommandTest.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/RemoteServerControlCommandTest.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/RemoteServerControlCommandTest.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,89 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands; + +import org.apache.geronimo.gshell.command.CommandExecutor +import org.apache.geronimo.gshell.command.IO + +import org.apache.geronimo.testsupport.TestSupport + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +class RemoteServerControlCommandTest extends GroovyTestCase { + + def command + def executedCommand + + protected void setUp() { + def testSupport = new GroovyTestSupport() + + File configurationFile = testSupport.resolveFile('src/test/resources/etc/server-configuration.xml') + + command = new RemoteServerControlCommand([io: new IO(), configurationFileName: configurationFile.absolutePath]) + command.executor = { executedCommand = it } as CommandExecutor + } + + void testConfigurationFileDoesNotExistThrowsISE() { + shouldFail(IllegalStateException.class) { + command.configurationFileName = 'doesNotExist' + command.doExecute() + } + } + + void testServerIsUndefinedThrowsIAE() { + shouldFail(IllegalArgumentException.class) { + command.serverName = 'undefined' + command.doExecute() + } + } + + void testServerIsDefinedWithUndefinedHostThrowsIAE() { + shouldFail(IllegalArgumentException.class) { + command.serverName = 'serverWithUndefinedHost' + command.doExecute() + } + } + + void testControlIsUndefinedThrowsISE() { + shouldFail(IllegalStateException.class) { + command.serverName = 'defaultServer' + command.control = 'undefined' + command.doExecute() + } + } + + void testRemoteLoginCmdIsUndefinedThrowsISE() { + shouldFail(IllegalStateException.class) { + command.serverName = 'serverWithUndefinedRemoteLoginCmd' + command.doExecute() + } + } + + void testRemoteControlOK() { + command.serverName = 'defaultServer' + command.control = 'start' + command.doExecute() + + assert 'rshCommand start-server' == executedCommand + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/UnaliasCommandTest.groovy URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/UnaliasCommandTest.groovy?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/UnaliasCommandTest.groovy (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/groovy/org/apache/geronimo/commands/UnaliasCommandTest.groovy Tue Dec 4 02:46:27 2007 @@ -0,0 +1,71 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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 org.apache.geronimo.commands; + +import org.apache.geronimo.gshell.command.IO + +import org.apache.geronimo.testsupport.TestSupport + +/** + * + * @version $Rev: 580864 $ $Date: 2007-09-30 23:47:39 -0700 (Sun, 30 Sep 2007) $ + */ +class UnaliasCommandTest extends GroovyTestCase { + + def command + + protected void setUp() { + def testSupport = new GroovyTestSupport() + + File baseFile = testSupport.resolveFile('src/test/resources/etc/aliases.xml') + def lines = baseFile.readLines() + + def workingFile = testSupport.resolveFile('build/etc/aliases.xml') + workingFile.delete() + workingFile.parentFile.mkdirs() + workingFile.createNewFile() + workingFile.withPrintWriter { pw -> + lines.each { pw.println(it) } + } + + command = new UnaliasCommand([io: new IO(), aliasFileName: workingFile.absolutePath]) + } + + void testAliasFileDoesNotExistThrowsISE() { + shouldFail(IllegalStateException.class) { + command.aliasFileName = 'doesNotExist' + command.doExecute() + } + } + + void testNoAliasArgumentThrowsIAE() { + shouldFail(IllegalArgumentException.class) { + command.doExecute() + } + } + + void testUnalias() { + command.aliasName = 'start_DEFAULT_SERVER' + assertTrue(command.doExecute()) + +// assertFalse(command.doExecute()) + } + +} Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/aliases.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/aliases.xml?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/aliases.xml (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/aliases.xml Tue Dec 4 02:46:27 2007 @@ -0,0 +1,11 @@ + + + start-server -d + + + stop-server + + + a script + + \ No newline at end of file Added: geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/server-configuration.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/server-configuration.xml?rev=600872&view=auto ============================================================================== --- geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/server-configuration.xml (added) +++ geronimo/server/trunk/framework/modules/geronimo-commands/src/test/resources/etc/server-configuration.xml Tue Dec 4 02:46:27 2007 @@ -0,0 +1,30 @@ + + + + + + rshCommand + + + + + rshCommand + + + + + + + + start-server + stop-server + + + + + + + + + + Modified: geronimo/server/trunk/pom.xml URL: http://svn.apache.org/viewvc/geronimo/server/trunk/pom.xml?rev=600872&r1=600871&r2=600872&view=diff ============================================================================== --- geronimo/server/trunk/pom.xml (original) +++ geronimo/server/trunk/pom.xml Tue Dec 4 02:46:27 2007 @@ -1575,13 +1575,49 @@ gshell-cli 1.0-alpha-1-SNAPSHOT - + + + org.apache.geronimo.gshell + gshell-whisper + 1.0-alpha-1-SNAPSHOT + + org.apache.geronimo.gshell.commands gshell-builtins 1.0-alpha-1-SNAPSHOT + + org.apache.geronimo.gshell.remote + gshell-remote-client + 1.0-alpha-1-SNAPSHOT + + + + org.apache.geronimo.gshell.remote + gshell-remote-common + 1.0-alpha-1-SNAPSHOT + + + + org.apache.geronimo.gshell.remote + gshell-remote-server + 1.0-alpha-1-SNAPSHOT + + + + org.apache.mina + mina-core + 1.1.2 + + + + org.apache.mina + mina-filter-ssl + 1.1.2 + + org.codehaus.groovy groovy-all