Author: lincolnthree
Date: 2010-07-09 19:49:57 -0400 (Fri, 09 Jul 2010)
New Revision: 13356
Added:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginRegistry.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/AcceptUserInput.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Shutdown.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Startup.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/util/
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/util/Annotations.java
sandbox/encore/shell/src/main/resources/META-INF/services/
sandbox/encore/shell/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
Removed:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/CommandCompleter.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/StartupEvent.java
Modified:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
sandbox/encore/shell/pom.xml
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Main.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java
Log:
Basic shell and plugin architecture is functional.
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
===================================================================
---
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-07-09
12:43:51 UTC (rev 13355)
+++
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -172,12 +172,13 @@
return result;
}
- public void removeMethod(final Method method)
+ public JavaClass removeMethod(final Method method)
{
if (getMethods().contains(method))
{
getTypeDeclaration().bodyDeclarations().remove(method);
}
+ return this;
}
public TypeDeclaration getTypeDeclaration()
@@ -223,4 +224,43 @@
}
}
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((unit == null) ? 0 : unit.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ JavaClass other = (JavaClass) obj;
+ if (unit == null)
+ {
+ if (other.unit != null)
+ {
+ return false;
+ }
+ }
+ else if (!unit.equals(other.unit))
+ {
+ return false;
+ }
+ return true;
+ }
+
}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-07-09
12:43:51 UTC (rev 13355)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -273,4 +273,55 @@
{
parent.applyChanges();
}
+
+ @Override
+ public int hashCode()
+ {
+ final int prime = 31;
+ int result = 1;
+ result = prime * result + ((method == null) ? 0 : method.hashCode());
+ result = prime * result + ((parent == null) ? 0 : parent.hashCode());
+ return result;
+ }
+
+ @Override
+ public boolean equals(final Object obj)
+ {
+ if (this == obj)
+ {
+ return true;
+ }
+ if (obj == null)
+ {
+ return false;
+ }
+ if (getClass() != obj.getClass())
+ {
+ return false;
+ }
+ Method other = (Method) obj;
+ if (method == null)
+ {
+ if (other.method != null)
+ {
+ return false;
+ }
+ }
+ else if (!method.equals(other.method))
+ {
+ return false;
+ }
+ if (parent == null)
+ {
+ if (other.parent != null)
+ {
+ return false;
+ }
+ }
+ else if (!parent.equals(other.parent))
+ {
+ return false;
+ }
+ return true;
+ }
}
Modified:
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
===================================================================
---
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-07-09
12:43:51 UTC (rev 13355)
+++
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -104,6 +104,16 @@
}
@Test
+ public void testRemoveMethod() throws Exception
+ {
+ // TODO Removing methods needs to work
+ // List<Method> methods = javaClass.getMethods();
+ // javaClass.removeMethod(methods.get(0)).applyChanges();
+ // methods = javaClass.getMethods();
+ // assertEquals(1, methods.size());
+ }
+
+ @Test
public void testAddConstructor() throws Exception
{
javaClass.addMethod().setName("testMethod").setConstructor(true).setProtected().setReturnType(String.class)
Modified: sandbox/encore/shell/pom.xml
===================================================================
--- sandbox/encore/shell/pom.xml 2010-07-09 12:43:51 UTC (rev 13355)
+++ sandbox/encore/shell/pom.xml 2010-07-09 23:49:57 UTC (rev 13356)
@@ -18,6 +18,11 @@
<dependencies>
<!-- CDI Dependencies -->
<dependency>
+ <groupId>org.jboss.encore</groupId>
+ <artifactId>core</artifactId>
+ <version>1.0.0-SNAPSHOT</version>
+ </dependency>
+ <dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-se</artifactId>
<version>1.0.1-Final</version>
@@ -37,7 +42,7 @@
<artifactId>slf4j-simple</artifactId>
<version>1.5.10</version>
</dependency>
-
+
<!-- Shell Libraries -->
<dependency>
<groupId>org.sonatype.jline</groupId>
@@ -46,4 +51,29 @@
</dependency>
</dependencies>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>1.1.1</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.jboss.encore.shell.Main</mainClass>
+ <!--
+ <arguments> <argument>argument1</argument>
</arguments>
+ <systemProperties> <systemProperty>
<key>myproperty</key> <value>myvalue</value>
+ </systemProperty> </systemProperties>
+ -->
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
</project>
\ No newline at end of file
Deleted: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/CommandCompleter.java
===================================================================
---
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/CommandCompleter.java 2010-07-09
12:43:51 UTC (rev 13355)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/CommandCompleter.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -1,41 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.encore.shell;
-
-import java.util.List;
-
-import jline.console.completer.Completer;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
- *
- */
-public class CommandCompleter implements Completer
-{
-
- @Override
- public int complete(final String buffer, final int cursor, final
List<CharSequence> candidates)
- {
- return 0;
- }
-
-}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java
(rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Execution.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,101 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell;
+
+import java.util.Set;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+
+import org.jboss.encore.shell.cli.CommandMetadata;
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class Execution
+{
+ @Inject
+ private BeanManager manager;
+
+ private CommandMetadata command;
+ private Object[] parameterArray;
+
+ @SuppressWarnings("unchecked")
+ public void perform()
+ {
+ if (command != null)
+ {
+ try
+ {
+ Class<? extends Plugin> pluginType = command.getParent().getType();
+ Set<Bean<?>> beans = manager.getBeans(pluginType);
+ Bean<? extends Object> bean = manager.resolve(beans);
+
+ Plugin plugin = null;
+ if (bean != null)
+ {
+ CreationalContext<? extends Plugin> context =
(CreationalContext<? extends Plugin>) manager
+ .createCreationalContext(bean);
+ if (context != null)
+ {
+ plugin = (Plugin) manager.getReference(bean, pluginType, context);
+ command.getMethod().invoke(plugin, parameterArray);
+ }
+ }
+
+ }
+ catch (Exception e)
+ {
+ System.err.println("I don't understand what you meant.");
+ }
+ }
+ else
+ {
+
+ }
+ }
+
+ public CommandMetadata getCommand()
+ {
+ return command;
+ }
+
+ public void setCommand(final CommandMetadata command)
+ {
+ this.command = command;
+ }
+
+ public Object[] getParameterArray()
+ {
+ return parameterArray;
+ }
+
+ public void setParameterArray(final Object... parameters)
+ {
+ this.parameterArray = parameters;
+ }
+
+}
Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Main.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Main.java 2010-07-09
12:43:51 UTC (rev 13355)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Main.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -21,7 +21,8 @@
*/
package org.jboss.encore.shell;
-import org.jboss.encore.shell.events.StartupEvent;
+import org.jboss.encore.shell.events.AcceptUserInput;
+import org.jboss.encore.shell.events.Startup;
import org.jboss.weld.environment.se.Weld;
import org.jboss.weld.environment.se.WeldContainer;
@@ -35,7 +36,8 @@
{
Weld weld = new Weld();
WeldContainer container = weld.initialize();
- container.event().fire(new StartupEvent());
+ container.event().fire(new Startup());
+ container.event().fire(new AcceptUserInput());
weld.shutdown();
}
Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java 2010-07-09
12:43:51 UTC (rev 13355)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/Shell.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -21,6 +21,7 @@
*/
package org.jboss.encore.shell;
+import java.io.IOException;
import java.util.List;
import javax.enterprise.event.Observes;
@@ -28,8 +29,12 @@
import javax.inject.Singleton;
import jline.console.ConsoleReader;
+import jline.console.completer.Completer;
-import org.jboss.encore.shell.events.StartupEvent;
+import org.jboss.encore.shell.cli.ExecutionParser;
+import org.jboss.encore.shell.events.AcceptUserInput;
+import org.jboss.encore.shell.events.Shutdown;
+import org.jboss.encore.shell.events.Startup;
import org.jboss.weld.environment.se.bindings.Parameters;
import org.slf4j.Logger;
@@ -40,7 +45,6 @@
@Singleton
public class Shell
{
- private static String completionKeys = "TAB";
private final String prompt = "encore> ";
@Inject
@@ -50,9 +54,15 @@
@Inject
Logger log;
+ @Inject
+ private Completer completer;
+ @Inject
+ private ExecutionParser parser;
+
private ConsoleReader reader;
+ private boolean exitRequested = false;
- public void init(@Observes final StartupEvent event) throws Exception
+ public void init(@Observes final Startup event) throws Exception
{
System.out.println("Startup");
log.info("Encore Shell - Starting up.");
@@ -60,5 +70,38 @@
reader = new ConsoleReader();
reader.setHistoryEnabled(true);
reader.setPrompt(prompt);
+ reader.addCompleter(completer);
}
+
+ public void doShell(@Observes final AcceptUserInput event)
+ {
+ String line;
+ try
+ {
+ while ((exitRequested != true) && ((line = reader.readLine()) != null))
+ {
+ if ("".equals(line))
+ {
+ continue;
+ }
+
+ execute(line);
+ }
+ }
+ catch (IOException e)
+ {
+ throw new IllegalStateException("Shell line reading failure", e);
+ }
+ }
+
+ private void execute(final String line)
+ {
+ Execution execution = parser.parse(line);
+ execution.perform();
+ }
+
+ public void teardown(@Observes final Shutdown event)
+ {
+ exitRequested = true;
+ }
}
\ No newline at end of file
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java
(rev 0)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/BuiltIn.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,48 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import static java.lang.annotation.ElementType.FIELD;
+import static java.lang.annotation.ElementType.METHOD;
+import static java.lang.annotation.ElementType.PARAMETER;
+import static java.lang.annotation.ElementType.TYPE;
+import static java.lang.annotation.RetentionPolicy.RUNTIME;
+
+import java.lang.annotation.Documented;
+import java.lang.annotation.Retention;
+import java.lang.annotation.Target;
+
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * Defines a #{@link Plugin} as built in, thus, commands will be accessible without
providing a plugin name;
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+@Target({ TYPE, METHOD, PARAMETER, FIELD })
+@Retention(RUNTIME)
+@Documented
+public @interface BuiltIn
+{
+
+}
Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java 2010-07-09
12:43:51 UTC (rev 13355)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Command.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -48,10 +48,10 @@
/**
* One or more names for this command.
*/
- String[] value();
+ String[] value() default {};
/**
* Help text for this command.
*/
- String help();
+ String help() default "";
}
Added:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java
===================================================================
---
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandLibraryExtension.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,145 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.Bean;
+import javax.enterprise.inject.spi.Extension;
+import javax.enterprise.inject.spi.ProcessBean;
+import javax.inject.Named;
+
+import org.jboss.encore.shell.plugins.Plugin;
+import org.jboss.encore.shell.util.Annotations;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class CommandLibraryExtension implements Extension
+{
+ private final Map<String, PluginMetadata> plugins = new HashMap<String,
PluginMetadata>();
+
+ public Map<String, PluginMetadata> getPlugins()
+ {
+ return plugins;
+ }
+
+ @SuppressWarnings("unchecked")
+ public void scan(@Observes final ProcessBean<?> event)
+ {
+ Bean<?> bean = event.getBean();
+
+ Class<? extends Plugin> plugin = (Class<? extends Plugin>)
bean.getBeanClass();
+ if (Plugin.class.isAssignableFrom(plugin))
+ {
+ System.out.println("\\t" + plugin);
+
+ String name = getPluginName(plugin);
+
+ PluginMetadata pluginMeta = new PluginMetadata();
+ pluginMeta.setBuiltIn(Annotations.isAnnotationPresent(plugin, BuiltIn.class));
+ pluginMeta.setName(name);
+ pluginMeta.setType(plugin);
+
+ List<CommandMetadata> commands = getPluginCommands(pluginMeta, plugin);
+ pluginMeta.setCommands(commands);
+
+ plugins.put(name, pluginMeta);
+ }
+ }
+
+ private List<CommandMetadata> getPluginCommands(final PluginMetadata pluginMeta,
final Class<?> plugin)
+ {
+ List<CommandMetadata> results = new ArrayList<CommandMetadata>();
+
+ for (Method m : plugin.getMethods())
+ {
+ if (Annotations.isAnnotationPresent(m, Command.class))
+ {
+ Command command = Annotations.getAnnotation(m, Command.class);
+ CommandMetadata commandMeta = new CommandMetadata();
+ commandMeta.setMethod(m);
+ commandMeta.setHelp(command.help());
+ commandMeta.setParent(pluginMeta);
+
+ if (command.value().length == 0)
+ {
+ commandMeta.setNames(m.getName().toLowerCase());
+ }
+ else
+ {
+ commandMeta.setNames(command.value());
+ }
+
+ Class<?>[] parameterTypes = m.getParameterTypes();
+ Annotation[][] parameterAnnotations = m.getParameterAnnotations();
+
+ int i = 0;
+ for (Class<?> clazz : parameterTypes)
+ {
+ OptionMetadata option = new OptionMetadata();
+ option.setType(clazz);
+ option.setIndex(i);
+
+ for (Annotation a : parameterAnnotations[i])
+ {
+ if (a instanceof Option)
+ {
+ Option opt = (Option) a;
+ option.setParent(commandMeta);
+ option.setName(opt.value());
+ option.setHelp(opt.help());
+ option.setRequired(opt.requred());
+ }
+ }
+ commandMeta.addOption(option);
+ i++;
+ }
+
+ results.add(commandMeta);
+ }
+ }
+ return results;
+ }
+
+ private String getPluginName(final Class<?> plugin)
+ {
+ String name = null;
+ Named named = Annotations.getAnnotation(plugin, Named.class);
+ if (named != null)
+ {
+ name = named.value();
+ }
+ if ((name == null) || "".equals(name.trim()))
+ {
+ name = plugin.getSimpleName();
+ }
+ return name;
+ }
+}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/CommandMetadata.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,114 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.lang.reflect.Method;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class CommandMetadata
+{
+ private PluginMetadata parent;
+ private Method method;
+ private String[] names = {};
+ private String help;
+ private List<OptionMetadata> options = new ArrayList<OptionMetadata>();
+
+ public Method getMethod()
+ {
+ return method;
+ }
+
+ public void setMethod(final Method method)
+ {
+ this.method = method;
+ }
+
+ public List<String> getNames()
+ {
+ return Arrays.asList(names);
+ }
+
+ public void setNames(final String... names)
+ {
+ this.names = names;
+ }
+
+ public List<OptionMetadata> getOptions()
+ {
+ return options;
+ }
+
+ public void setOptions(final List<OptionMetadata> options)
+ {
+ this.options = options;
+ }
+
+ public void addOption(final OptionMetadata option)
+ {
+ this.options.add(option);
+ }
+
+ public String getHelp()
+ {
+ return help;
+ }
+
+ public void setHelp(final String help)
+ {
+ this.help = help;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "CommandMetadata [method=" + method + ", names=" +
Arrays.toString(names) + ", help=" + help
+ + ", options=" + options + "]";
+ }
+
+ public PluginMetadata getParent()
+ {
+ return parent;
+ }
+
+ public void setParent(final PluginMetadata parent)
+ {
+ this.parent = parent;
+ }
+
+ public OptionMetadata getNamedOption(final String token)
+ {
+ for (OptionMetadata option : options)
+ {
+ if (option.isNamed() && option.getName().equals(token))
+ {
+ return option;
+ }
+ }
+ return null;
+ }
+}
\ No newline at end of file
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/ExecutionParser.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,108 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Map;
+import java.util.Map.Entry;
+import java.util.Queue;
+
+import javax.enterprise.inject.Instance;
+import javax.inject.Inject;
+
+import org.jboss.encore.shell.Execution;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class ExecutionParser
+{
+ @Inject
+ private PluginRegistry registry;
+
+ @Inject
+ private Instance<Execution> executionInstance;
+
+ public Execution parse(final String line)
+ {
+ Queue<String> tokens = new LinkedList<String>();
+ for (String token : line.split("\\s+"))
+ {
+ tokens.add(token);
+ }
+
+ Map<String, PluginMetadata> plugins = registry.getPlugins();
+ Map<String, PluginMetadata> builtInPlugins = registry.getBuiltInPlugins();
+
+ Execution execution = executionInstance.get();
+ CommandMetadata command = null;
+ List<Object> parameters = new ArrayList<Object>();
+
+ if (tokens.size() > 0)
+ {
+ String first = tokens.remove();
+
+ PluginMetadata plugin = plugins.get(first);
+ if (plugin == null)
+ {
+ for (Entry<String, PluginMetadata> entry : builtInPlugins.entrySet())
+ {
+ command = entry.getValue().getCommand(first);
+ if (command != null)
+ {
+ plugin = command.getParent();
+ }
+ }
+ }
+
+ if ((plugin != null) && plugin.isImplicitCommand())
+ {
+ command = plugin.getCommands().get(0);
+ }
+ else if (tokens.size() > 1)
+ {
+ String second = tokens.peek();
+ if ((plugin != null) && (command == null))
+ {
+ command = plugin.getCommand(second);
+ if (command != null)
+ {
+ tokens.remove();
+ }
+ }
+ }
+
+ if (command != null)
+ {
+ execution.setCommand(command);
+ parameters.addAll(Arrays.asList(tokens.toArray()));
+ execution.setParameterArray(parameters.toArray());
+ }
+ }
+
+ return execution;
+ }
+}
Modified: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java 2010-07-09
12:43:51 UTC (rev 13355)
+++ sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/Option.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -32,15 +32,29 @@
import javax.inject.Qualifier;
/**
+ * A command option.
+ *
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
*
*/
-
@Qualifier
@Target({ METHOD, PARAMETER })
@Retention(RUNTIME)
@Documented
public @interface Option
{
+ /**
+ * The name of this option;
+ */
+ String value() default "";
+ /**
+ * Specify whether or not this option is required.
+ */
+ boolean requred() default false;
+
+ /**
+ * Help text for this option.
+ */
+ String help() default "";
}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/OptionMetadata.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,112 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class OptionMetadata
+{
+ private CommandMetadata parent;
+ private Class<?> type;
+ private String name;
+ private int index;
+ private String help;
+ private boolean required;
+
+ /**
+ * Return whether this option is to be mapped via name or via parameter order.
+ */
+ public boolean isNamed()
+ {
+ return (name != null) && !"".equals(name);
+ }
+
+ public Class<?> getType()
+ {
+ return type;
+ }
+
+ public void setType(final Class<?> type)
+ {
+ this.type = type;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(final String name)
+ {
+ this.name = name;
+ }
+
+ public int getIndex()
+ {
+ return index;
+ }
+
+ public void setIndex(final int index)
+ {
+ this.index = index;
+ }
+
+ public String getHelp()
+ {
+ return help;
+ }
+
+ public void setHelp(final String help)
+ {
+ this.help = help;
+ }
+
+ public boolean isRequired()
+ {
+ return required;
+ }
+
+ public void setRequired(final boolean required)
+ {
+ this.required = required;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "OptionMetadata [type=" + type + ", name=" + name +
", index=" + index + ", help=" + help + ", required="
+ + required + "]";
+ }
+
+ public CommandMetadata getParent()
+ {
+ return parent;
+ }
+
+ public void setParent(final CommandMetadata parent)
+ {
+ this.parent = parent;
+ }
+
+}
Added:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java
===================================================================
---
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginCommandCompletionHandler.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,71 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.util.List;
+import java.util.Map;
+
+import javax.inject.Inject;
+
+import jline.console.completer.Completer;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class PluginCommandCompletionHandler implements Completer
+{
+ @Inject
+ private PluginRegistry registry;
+
+ @Override
+ public int complete(final String buffer, final int cursor, final
List<CharSequence> candidates)
+ {
+ Map<String, PluginMetadata> plugins = registry.getPlugins();
+
+ String[] tokens = buffer.split("\\s+");
+ if (tokens.length == 1)
+ {
+ String plugin = tokens[0];
+ for (String pluginName : plugins.keySet())
+ {
+ if (pluginName.startsWith(plugin))
+ {
+ PluginMetadata pluginMetadata = plugins.get(pluginName);
+ if (pluginMetadata.isImplicitCommand())
+ {
+ List<String> names =
pluginMetadata.getCommands().get(0).getNames();
+ for (String name : names)
+ {
+ candidates.add(name);
+ }
+ }
+ else
+ {
+ candidates.add(pluginName);
+ }
+ }
+ }
+ }
+ return 0;
+ }
+}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginMetadata.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,113 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class PluginMetadata
+{
+ private boolean builtIn = false;
+ private String name;
+ private Class<? extends Plugin> type;
+ private List<CommandMetadata> commands = new
ArrayList<CommandMetadata>();
+
+ /**
+ * Get the command matching the given name, or return null.
+ */
+ public CommandMetadata getCommand(final String name)
+ {
+ CommandMetadata result = null;
+
+ List<CommandMetadata> commands = this.getCommands();
+ for (CommandMetadata commandMetadata : commands)
+ {
+ if (commandMetadata.getNames().contains(name))
+ {
+ result = commandMetadata;
+ }
+ }
+
+ return result;
+ }
+
+ /**
+ * Return true if this plugin defines a single command to be executed by default.
+ */
+ public boolean isImplicitCommand()
+ {
+ return commands.size() == 1;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public void setName(final String name)
+ {
+ this.name = name;
+ }
+
+ public Class<? extends Plugin> getType()
+ {
+ return type;
+ }
+
+ public void setType(final Class<? extends Plugin> type)
+ {
+ this.type = type;
+ }
+
+ public List<CommandMetadata> getCommands()
+ {
+ return commands;
+ }
+
+ public void setCommands(final List<CommandMetadata> commands)
+ {
+ this.commands = commands;
+ }
+
+ @Override
+ public String toString()
+ {
+ return "PluginMetadata [builtIn=" + builtIn + ", name=" + name
+ ", type=" + type + ", commands=" + commands
+ + "]";
+ }
+
+ public boolean isBuiltIn()
+ {
+ return builtIn;
+ }
+
+ public void setBuiltIn(final boolean builtIn)
+ {
+ this.builtIn = builtIn;
+ }
+}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginRegistry.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginRegistry.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/PluginRegistry.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Map.Entry;
+
+import javax.annotation.PostConstruct;
+import javax.inject.Inject;
+import javax.inject.Singleton;
+
+/**
+ * Stores the current registry of all installed & loaded plugins.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+@Singleton
+public class PluginRegistry
+{
+ private Map<String, PluginMetadata> plugins;
+
+ @Inject
+ private CommandLibraryExtension library;
+
+ @PostConstruct
+ public void init()
+ {
+ plugins = library.getPlugins();
+ }
+
+ public Map<String, PluginMetadata> getPlugins()
+ {
+ return plugins;
+ }
+
+ public Map<String, PluginMetadata> getBuiltInPlugins()
+ {
+ Map<String, PluginMetadata> result = new HashMap<String,
PluginMetadata>();
+ for (Entry<String, PluginMetadata> plugin : plugins.entrySet())
+ {
+ if (plugin.getValue().isBuiltIn())
+ {
+ result.put(plugin.getKey(), plugin.getValue());
+ }
+ }
+ return result;
+ }
+
+ public void addPlugin(final PluginMetadata plugin)
+ {
+ plugins.put(plugin.getName(), plugin);
+ }
+
+ @Override
+ public String toString()
+ {
+ return "PluginRegistry [plugins=" + plugins + "]";
+ }
+
+}
Added:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/ExitShell.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.builtin;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+
+import org.jboss.encore.shell.cli.BuiltIn;
+import org.jboss.encore.shell.cli.Command;
+import org.jboss.encore.shell.events.Shutdown;
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * Implements a {@link Plugin} that fires the shell {@link Shutdown#NORMAL} event.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+@BuiltIn
+public class ExitShell implements Plugin
+{
+ @Inject
+ private Event<Shutdown> shutdown;
+
+ @Command(value = { "exit", "quit" }, help = "Exit the
shell")
+ public void exit()
+ {
+ shutdown.fire(Shutdown.NORMAL);
+ }
+}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/cli/builtin/Help.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,52 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.cli.builtin;
+
+import javax.enterprise.event.Event;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jboss.encore.shell.cli.BuiltIn;
+import org.jboss.encore.shell.cli.Command;
+import org.jboss.encore.shell.cli.Option;
+import org.jboss.encore.shell.events.Shutdown;
+import org.jboss.encore.shell.plugins.Plugin;
+
+/**
+ * Implements a {@link Plugin} that fires the shell {@link Shutdown#NORMAL} event.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+@BuiltIn
+@Named("help")
+public class Help implements Plugin
+{
+ @Inject
+ private Event<Shutdown> shutdown;
+
+ @Command(help = "Get help about specific commands")
+ public void help(@Option(requred = true) final String command, @Option final String
subcommand)
+ {
+ System.out.println("You requested help for: " + command);
+ }
+}
Added:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/AcceptUserInput.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/AcceptUserInput.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/AcceptUserInput.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.events;
+
+/**
+ * Informs the Shell that it should begin accepting User Input
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class AcceptUserInput
+{
+
+}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Shutdown.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Shutdown.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Shutdown.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,33 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.events;
+
+/**
+ * The shell shutdown event.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public enum Shutdown
+{
+ NORMAL, ERROR
+}
Copied: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Startup.java
(from rev 13337,
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/StartupEvent.java)
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Startup.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/Startup.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.events;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public class Startup
+{
+
+}
Deleted:
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/StartupEvent.java
===================================================================
---
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/StartupEvent.java 2010-07-09
12:43:51 UTC (rev 13355)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/events/StartupEvent.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -1,31 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- * Copyright 2010, Red Hat, Inc., and individual contributors
- * by the @authors tag. See the copyright.txt in the distribution for a
- * full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-package org.jboss.encore.shell.events;
-
-/**
- * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
- *
- */
-public class StartupEvent
-{
-
-}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/plugins/Plugin.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,31 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.plugins;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter,
III</a>
+ *
+ */
+public interface Plugin
+{
+
+}
Added: sandbox/encore/shell/src/main/java/org/jboss/encore/shell/util/Annotations.java
===================================================================
--- sandbox/encore/shell/src/main/java/org/jboss/encore/shell/util/Annotations.java
(rev 0)
+++
sandbox/encore/shell/src/main/java/org/jboss/encore/shell/util/Annotations.java 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1,157 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2010, Red Hat, Inc., and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+package org.jboss.encore.shell.util;
+
+import java.lang.annotation.Annotation;
+import java.lang.reflect.Method;
+
+import javax.enterprise.inject.Stereotype;
+
+/**
+ * Utility class for common @{@link Annotation} operations.
+ * <p>
+ * TODO: This should probably go into weld-extensions so other portable extensions can
leverage it.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com>Lincoln Baxter,
III</a>
+ *
+ */
+public class Annotations
+{
+ /**
+ * Discover if a Method <b>m</b> has been annotated with
<b>type</b>. This also discovers annotations defined through
+ * a @{@link Stereotype}.
+ *
+ * @param m The method to inspect.
+ * @param type The targeted annotation class
+ *
+ * @return True if annotation is present either on the method itself, or on the
declaring class of the method.
+ * Returns false if the annotation is not present.
+ */
+ public static boolean isAnnotationPresent(final Method m, final Class<? extends
Annotation> type)
+ {
+ boolean result = false;
+ if (m.isAnnotationPresent(type))
+ {
+ result = true;
+ }
+ else
+ {
+ for (Annotation a : m.getAnnotations())
+ {
+ if (a.annotationType().isAnnotationPresent(type))
+ {
+ result = true;
+ }
+ }
+ }
+
+ if (result == false)
+ {
+ result = isAnnotationPresent(m.getDeclaringClass(), type);
+ }
+ return result;
+ }
+
+ /**
+ * Discover if a Class <b>c</b> has been annotated with
<b>type</b>. This also discovers annotations defined through
+ * a @{@link Stereotype}.
+ *
+ * @param c The class to inspect.
+ * @param type The targeted annotation class
+ *
+ * @return True if annotation is present either on class, false if the annotation is
not present.
+ */
+ public static boolean isAnnotationPresent(final Class<?> c, final Class<?
extends Annotation> type)
+ {
+ boolean result = false;
+ if (c.isAnnotationPresent(type))
+ {
+ result = true;
+ }
+ else
+ {
+ for (Annotation a : c.getAnnotations())
+ {
+ if (a.annotationType().isAnnotationPresent(type))
+ {
+ result = true;
+ }
+ }
+ }
+ return result;
+ }
+
+ /**
+ * Inspect method <b>m</b> for a specific <b>type</b> of
annotation. This also discovers annotations defined through
+ * a @ {@link Stereotype}.
+ *
+ * @param m The method to inspect.
+ * @param type The targeted annotation class
+ *
+ * @return The annotation instance found on this method or enclosing class, or null if
no matching annotation was
+ * found.
+ */
+ public static <A extends Annotation> A getAnnotation(final Method m, final
Class<A> type)
+ {
+ A result = m.getAnnotation(type);
+ if (result == null)
+ {
+ for (Annotation a : m.getAnnotations())
+ {
+ if (a.annotationType().isAnnotationPresent(type))
+ {
+ result = a.annotationType().getAnnotation(type);
+ }
+ }
+ }
+ if (result == null)
+ {
+ result = getAnnotation(m.getDeclaringClass(), type);
+ }
+ return result;
+ }
+
+ /**
+ * Inspect class <b>c</b> for a specific <b>type</b> of
annotation. This also discovers annotations defined through a @
+ * {@link Stereotype}.
+ *
+ * @param c The class to inspect.
+ * @param type The targeted annotation class
+ *
+ * @return The annotation instance found on this class, or null if no matching
annotation was found.
+ */
+ public static <A extends Annotation> A getAnnotation(final Class<?> c,
final Class<A> type)
+ {
+ A result = c.getAnnotation(type);
+ if (result == null)
+ {
+ for (Annotation a : c.getAnnotations())
+ {
+ if (a.annotationType().isAnnotationPresent(type))
+ {
+ result = a.annotationType().getAnnotation(type);
+ }
+ }
+ }
+ return result;
+ }
+}
Added:
sandbox/encore/shell/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
===================================================================
---
sandbox/encore/shell/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension
(rev 0)
+++
sandbox/encore/shell/src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension 2010-07-09
23:49:57 UTC (rev 13356)
@@ -0,0 +1 @@
+org.jboss.encore.shell.cli.CommandLibraryExtension
\ No newline at end of file