Seam SVN: r13356 - in sandbox/encore: core/src/test/java/org/jboss/encore/grammar/java and 9 other directories.
by seam-commits@lists.jboss.org
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
14 years, 5 months
Seam SVN: r13355 - branches/enterprise/JBPAPP_5_0/seam-gen/view/stylesheet.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2010-07-09 08:43:51 -0400 (Fri, 09 Jul 2010)
New Revision: 13355
Modified:
branches/enterprise/JBPAPP_5_0/seam-gen/view/stylesheet/theme.xcss
Log:
JBPAPP-4509 - added rich:comboBox styles into theme.xcss
Modified: branches/enterprise/JBPAPP_5_0/seam-gen/view/stylesheet/theme.xcss
===================================================================
--- branches/enterprise/JBPAPP_5_0/seam-gen/view/stylesheet/theme.xcss 2010-07-09 12:29:18 UTC (rev 13354)
+++ branches/enterprise/JBPAPP_5_0/seam-gen/view/stylesheet/theme.xcss 2010-07-09 12:43:51 UTC (rev 13355)
@@ -77,6 +77,34 @@
<u:selector name=".rich-table-subheadercell a:hover">
<u:style name="color" skin="calendarHolidaysTextColor"/>
</u:selector>
+ <!-- Richfaces styles -->
+ <u:selector name="input[type=text][class*=rich-combobox-button-icon]">
+ <u:style name="background-image">
+ <f:resource f:key="org.richfaces.renderkit.html.images.ComboBoxArrowImage" />
+ </u:style>
+ <u:style name="background-color" value="transparent"/>
+ </u:selector>
+
+ <u:selector name="input[type=text][class~=rich-combobox-button-icon-disabled]">
+ <u:style name="background-image">
+ <f:resource f:key="org.richfaces.renderkit.html.images.ComboBoxArrowImageDisable" />
+ </u:style>
+ <u:style name="background-color" value="transparent"/>
+ </u:selector>
+
+ <u:selector name="input[type=text][class*=rich-combobox-button-background]">
+ <u:style name="background-image">
+ <f:resource f:key="org.richfaces.renderkit.html.images.SpinnerButtonGradient"/>
+ </u:style>
+ <u:style name="background-color" skin="tabBackgroundColor"/>
+ </u:selector>
+
+ <u:selector name="input[type=text][class~=rich-combobox-button-pressed-background]">
+ <u:style name="background-image">
+ <f:resource f:key="org.richfaces.renderkit.html.images.ComboBoxButtonPressGradient"/>
+ </u:style>
+ <u:style name="background-color" skin="tabBackgroundColor"/>
+ </u:selector>
<!-- Define static styles in the CDATA block below (you can also move this block to the top) -->
<f:verbatim><![CDATA[
]]></f:verbatim>
14 years, 5 months
Seam SVN: r13354 - branches/enterprise/JBPAPP_5_0/build.
by seam-commits@lists.jboss.org
Author: manaRH
Date: 2010-07-09 08:29:18 -0400 (Fri, 09 Jul 2010)
New Revision: 13354
Modified:
branches/enterprise/JBPAPP_5_0/build/root.pom.xml
Log:
JBPAPP-4568 - added exclusions for activation.jar
Modified: branches/enterprise/JBPAPP_5_0/build/root.pom.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/build/root.pom.xml 2010-07-09 12:16:00 UTC (rev 13353)
+++ branches/enterprise/JBPAPP_5_0/build/root.pom.xml 2010-07-09 12:29:18 UTC (rev 13354)
@@ -312,6 +312,10 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
+ <exclusion>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ </exclusion>
</exclusions>
</dependency>
@@ -636,6 +640,12 @@
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3</version>
+ <exclusions>
+ <exclusion>
+ <groupId>javax.activation</groupId>
+ <artifactId>activation</artifactId>
+ </exclusion>
+ </exclusions>
</dependency>
<dependency>
14 years, 5 months
Seam SVN: r13352 - in sandbox/encore/core/src: main/java/org/jboss/encore/grammar/java and 5 other directories.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-07-08 16:56:09 -0400 (Thu, 08 Jul 2010)
New Revision: 13352
Added:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Internal.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java
Removed:
sandbox/encore/core/src/main/java/org/jboss/seam/encore/
sandbox/encore/core/src/test/java/org/jboss/seam/encore/
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/main/java/org/jboss/encore/grammar/java/ast/MethodFinderVisitor.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java
sandbox/encore/core/src/main/java/org/jboss/encore/model/Mutable.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
Log:
Starting to standardize the graph, code is much cleaner, added Import object.
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Internal.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Internal.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/Internal.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -0,0 +1,39 @@
+/*
+ * 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.grammar;
+
+/**
+ * Represents an object that stores implementation-specific data. This data must be accessible to other objects sharing
+ * the implementation, but should not be referenced by end-users.
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public interface Internal
+{
+ /**
+ * Returns the implementation-specific Object representing <code>this</code>. <b>Do not call this method</b> unless
+ * you are willing to risk breaking backwards compatibility if future versions do not use the same internal object
+ * implementations.
+ */
+ Object getInternal();
+}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Import.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -0,0 +1,100 @@
+/*
+ * 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.grammar.java;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.jboss.encore.grammar.Internal;
+import org.jboss.encore.model.Mutable;
+
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
+public class Import implements Internal, Mutable
+{
+
+ private JavaClass parent;
+ private AST ast = null;
+ private CompilationUnit cu = null;
+ private ImportDeclaration imprt = null;
+
+ private void init(final JavaClass parent)
+ {
+ this.parent = parent;
+ cu = (CompilationUnit) parent.getInternal();
+ ast = cu.getAST();
+ }
+
+ public Import(final JavaClass parent)
+ {
+ init(parent);
+ imprt = ast.newImportDeclaration();
+ }
+
+ public Import(final JavaClass parent, final Object internal)
+ {
+ init(parent);
+ imprt = (ImportDeclaration) internal;
+ }
+
+ public String getName()
+ {
+ return imprt.getName().getFullyQualifiedName();
+ }
+
+ public Import setName(final String name)
+ {
+ imprt.setName(ast.newName(tokenizeClassName(name)));
+ return this;
+ }
+
+ public boolean isStatic()
+ {
+ return imprt.isStatic();
+ }
+
+ public Import setStatic(final boolean value)
+ {
+ imprt.setStatic(value);
+ return this;
+ }
+
+ private String[] tokenizeClassName(final String className)
+ {
+ String[] result = className.split("\\.");
+ return result;
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ parent.applyChanges();
+ }
+
+ @Override
+ public Object getInternal()
+ {
+ return imprt;
+ }
+}
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-08 14:54:54 UTC (rev 13351)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -1,3 +1,24 @@
+/*
+ * 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.grammar.java;
import java.io.InputStream;
@@ -2,3 +23,2 @@
import java.util.ArrayList;
-import java.util.Collections;
import java.util.List;
@@ -13,18 +33,26 @@
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
import org.eclipse.jdt.internal.compiler.util.Util;
+import org.eclipse.jface.text.BadLocationException;
import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.MalformedTreeException;
import org.eclipse.text.edits.TextEdit;
import org.eclipse.text.edits.UndoEdit;
+import org.jboss.encore.grammar.Internal;
import org.jboss.encore.grammar.java.ast.MethodFinderVisitor;
import org.jboss.encore.grammar.java.ast.TypeDeclarationFinderVisitor;
+import org.jboss.encore.model.Mutable;
-public class JavaClass
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
+public class JavaClass implements Internal, Mutable
{
+ private final Stack<UndoEdit> undoStack = new Stack<UndoEdit>();
+
private Document document;
+ private CompilationUnit unit;
- private final Stack<UndoEdit> undoStack = new Stack<UndoEdit>();
-
/**
* Parses and process the java source code as a compilation unit and the result it abstract syntax tree (AST)
* representation and this action uses the third edition of java Language Specification.
@@ -37,7 +65,7 @@
try
{
char[] source = Util.getInputStreamAsCharArray(inputStream, inputStream.available(), "ISO8859_1");
- document = new Document(new String(source));
+ init(source);
}
catch (Exception e)
{
@@ -45,60 +73,56 @@
}
}
- public JavaClass(final char[] source)
+ public JavaClass(final String source)
{
- document = new Document(new String(source));
+ this(source.toCharArray());
}
- public JavaClass(final String source)
+ public JavaClass(final char[] source)
{
- this(source.toCharArray());
+ init(source);
}
- public CompilationUnit parse()
+ private void init(final char[] source)
{
+ document = new Document(new String(source));
ASTParser parser = ASTParser.newParser(AST.JLS3);
parser.setSource(document.get().toCharArray());
parser.setResolveBindings(true);
parser.setKind(ASTParser.K_COMPILATION_UNIT);
- CompilationUnit cu = (CompilationUnit) parser.createAST(null);
- return cu;
+ unit = (CompilationUnit) parser.createAST(null);
+ unit.recordModifications();
}
+ @SuppressWarnings("unchecked")
public Method addMethod()
{
- return new Method(this);
+ Method m = new Method(this);
+ getTypeDeclaration().bodyDeclarations().add(m.getInternal());
+ return m;
}
@SuppressWarnings("unchecked")
- public JavaClass addImport(final String className)
+ public Method addMethod(final String method)
{
- CompilationUnit cu = parse();
- try
- {
- AST ast = cu.getAST();
- cu.recordModifications();
- // ASTRewrite rewriter = ASTRewrite.create(ast);
- // ListRewrite lrw = rewriter.getListRewrite(cu, CompilationUnit.IMPORTS_PROPERTY);
+ Method m = new Method(this, method);
+ getTypeDeclaration().bodyDeclarations().add(m.getInternal());
+ return m;
+ }
- ImportDeclaration id = ast.newImportDeclaration();
- id.setName(ast.newName(tokenizeClassName(className)));
- cu.imports().add(id);
- TextEdit edit = cu.rewrite(document, null);
- UndoEdit undo = edit.apply(document);
+ @SuppressWarnings("unchecked")
+ public Import addImport(final String className)
+ {
+ Import imprt = new Import(this).setName(className);
+ unit.imports().add(imprt.getInternal());
+ return imprt;
+ }
- // lrw.insertLast(id, null);
- //
- // TextEdit edits = rewriter.rewriteAST(document, null);
- // UndoEdit undo = edits.apply(document);
- undoStack.add(undo);
-
- return this;
- }
- catch (Exception e)
+ public void addImports(final String... types)
+ {
+ for (String type : types)
{
- throw new RuntimeException("Could not add import: \"" + className +
- "\" to compilation unit: \"" + "\"", e);
+ addImport(type);
}
}
@@ -115,30 +139,28 @@
}
}
- private String[] tokenizeClassName(final String className)
- {
- String[] result = className.split("\\.");
- return result;
- }
-
public Stack<UndoEdit> getUndoStack()
{
return undoStack;
}
@SuppressWarnings("unchecked")
- public List<ImportDeclaration> getImports()
+ public List<Import> getImports()
{
- CompilationUnit unit = parse();
- List<ImportDeclaration> imports = unit.imports();
- return Collections.unmodifiableList(imports);
+ List<Import> results = new ArrayList<Import>();
+
+ for (ImportDeclaration i : (List<ImportDeclaration>) unit.imports())
+ {
+ results.add(new Import(this, i));
+ }
+
+ return results;
}
public List<Method> getMethods()
{
List<Method> result = new ArrayList<Method>();
- CompilationUnit unit = parse();
MethodFinderVisitor methodFinderVisitor = new MethodFinderVisitor();
unit.accept(methodFinderVisitor);
@@ -150,21 +172,55 @@
return result;
}
+ public void removeMethod(final Method method)
+ {
+ if (getMethods().contains(method))
+ {
+ getTypeDeclaration().bodyDeclarations().remove(method);
+ }
+ }
+
public TypeDeclaration getTypeDeclaration()
{
- CompilationUnit unit = parse();
TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
unit.accept(typeDeclarationFinder);
return typeDeclarationFinder.getTypeDeclarations().get(0);
}
- public Document getDocument()
+ public String getName()
{
- return document;
+ return getTypeDeclaration().getName().getIdentifier();
}
- public String getName()
+ @Override
+ public String toString()
{
- return getTypeDeclaration().getName().getIdentifier();
+ return document.get();
}
+
+ @Override
+ public Object getInternal()
+ {
+ return unit;
+ }
+
+ @Override
+ public void applyChanges()
+ {
+ try
+ {
+ TextEdit edit = unit.rewrite(document, null);
+ UndoEdit undo = edit.apply(document);
+ undoStack.add(undo);
+ }
+ catch (MalformedTreeException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (BadLocationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
}
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-08 14:54:54 UTC (rev 13351)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -21,102 +21,256 @@
*/
package org.jboss.encore.grammar.java;
+import java.util.ArrayList;
import java.util.List;
import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTNode;
import org.eclipse.jdt.core.dom.Block;
import org.eclipse.jdt.core.dom.CompilationUnit;
import org.eclipse.jdt.core.dom.MethodDeclaration;
-import org.eclipse.jface.text.Document;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.text.edits.UndoEdit;
+import org.eclipse.jdt.core.dom.Modifier;
+import org.eclipse.jdt.core.dom.Modifier.ModifierKeyword;
+import org.eclipse.jdt.core.dom.Statement;
+import org.jboss.encore.grammar.Internal;
+import org.jboss.encore.model.Mutable;
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
-public class Method
+public class Method implements Internal, Mutable
{
- private final JavaClass javaClass;
- private final AST ast;
- private final CompilationUnit cu;
- private final Document document;
- private MethodDeclaration method;
- private String body;
+ private JavaClass parent = null;
+ private AST ast = null;
+ private CompilationUnit cu = null;
+ private final MethodDeclaration method;
- public Method(final JavaClass javaClass)
+ private void init(final JavaClass parent)
{
- this.javaClass = javaClass;
- cu = javaClass.parse();
- cu.recordModifications();
- document = javaClass.getDocument();
+ this.parent = parent;
+ cu = (CompilationUnit) parent.getInternal();
ast = cu.getAST();
+ }
+
+ public Method(final JavaClass parent)
+ {
+ init(parent);
method = ast.newMethodDeclaration();
method.setConstructor(false);
}
- public Method(final JavaClass javaClass, final MethodDeclaration methodDeclaration)
+ public Method(final JavaClass parent, final Object internal)
{
- this(javaClass);
- method = methodDeclaration;
+ init(parent);
+ method = (MethodDeclaration) internal;
}
- public Method name(final String name)
+ public Method(final JavaClass parent, final String method)
{
- method.setName(ast.newSimpleName(name));
+ init(parent);
+
+ String stub = "public class Stub { " + method + " }";
+ JavaClass temp = new JavaClass(stub);
+ List<Method> methods = temp.getMethods();
+ MethodDeclaration newMethod = methods.get(0).getMethodDeclaration();
+ MethodDeclaration subtree = (MethodDeclaration) ASTNode.copySubtree(cu.getAST(), newMethod);
+ this.method = subtree;
+ }
+
+ @SuppressWarnings("unchecked")
+ public String getBody()
+ {
+ String result = "";
+
+ List<Statement> statements = (List<Statement>) method.getBody().getStructuralProperty(Block.STATEMENTS_PROPERTY);
+ for (Statement statement : statements)
+ {
+ result += statement + " ";
+ }
+
+ return result;
+ }
+
+ public Method setBody(final String body)
+ {
+ String stub = "public class Stub { public void method() {" + body + "} }";
+ JavaClass temp = new JavaClass(stub);
+ List<Method> methods = temp.getMethods();
+ Block block = methods.get(0).getMethodDeclaration().getBody();
+
+ block = (Block) ASTNode.copySubtree(method.getAST(), block);
+ method.setBody(block);
+
return this;
}
- public Method constructor(final boolean isConstructor)
+ public Method setConstructor(final boolean isConstructor)
{
method.setConstructor(isConstructor);
+ if (isConstructor())
+ {
+ method.setName(ast.newSimpleName(parent.getName()));
+ }
return this;
}
- public Method returnType(final Class<?> type)
+ public boolean isConstructor()
{
- return returnType(type.getSimpleName());
+ return method.isConstructor();
}
- public Method returnType(final String type)
+ @SuppressWarnings("unchecked")
+ public Method setAbstract()
{
- method.setReturnType2(ast.newSimpleType(ast.newSimpleName(type)));
+ method.modifiers().add(ast.newModifier(ModifierKeyword.ABSTRACT_KEYWORD));
return this;
}
- public Method body(final String body)
+ @SuppressWarnings("unchecked")
+ public Method setFinal()
{
- this.body = body;
- String stub = "public class Stub { public void method() {" + body + "} }";
- JavaClass temp = new JavaClass(stub);
- List<Method> methods = temp.getMethods();
- Block block = methods.get(0).getMethodDeclaration().getBody();
- method.setBody(block);
+ method.modifiers().add(ast.newModifier(ModifierKeyword.FINAL_KEYWORD));
return this;
}
- private MethodDeclaration getMethodDeclaration()
+ public String getName()
{
- return method;
+ return method.getName().toString();
}
+ public Method setName(final String name)
+ {
+ if (method.isConstructor())
+ {
+ throw new IllegalStateException("Cannot set the name of a constructor.");
+ }
+ method.setName(ast.newSimpleName(name));
+ return this;
+ }
+
+ public boolean isPackagePrivate()
+ {
+ return (!isPublic() && !isPrivate() && !isProtected());
+ }
+
@SuppressWarnings("unchecked")
- public JavaClass add()
+ public Method setPackagePrivate()
{
- try
+ List<Modifier> modifiers = method.modifiers();
+
+ List<Modifier> toBeRemoved = new ArrayList<Modifier>();
+ for (Modifier modifier : modifiers)
{
- boolean add = javaClass.getTypeDeclaration().bodyDeclarations().add(method);
+ if (modifier.isPrivate() || modifier.isProtected() || modifier.isPublic())
+ {
+ toBeRemoved.add(modifier);
+ }
+ }
- TextEdit edit = cu.rewrite(document, null);
- UndoEdit undo = edit.apply(document);
+ modifiers.removeAll(toBeRemoved);
- javaClass.getUndoStack().add(undo);
- return javaClass;
+ modifiers.add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
+ return this;
+ }
+
+ public boolean isPublic()
+ {
+ return hasModifier(ModifierKeyword.PUBLIC_KEYWORD);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method setPublic()
+ {
+ method.modifiers().add(ast.newModifier(ModifierKeyword.PUBLIC_KEYWORD));
+ return this;
+ }
+
+ public boolean isPrivate()
+ {
+ return hasModifier(ModifierKeyword.PRIVATE_KEYWORD);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method setPrivate()
+ {
+ method.modifiers().add(ast.newModifier(ModifierKeyword.PRIVATE_KEYWORD));
+ return this;
+ }
+
+ public boolean isProtected()
+ {
+ return hasModifier(ModifierKeyword.PROTECTED_KEYWORD);
+ }
+
+ @SuppressWarnings("unchecked")
+ public Method setProtected()
+ {
+ method.modifiers().add(ast.newModifier(ModifierKeyword.PROTECTED_KEYWORD));
+ return this;
+ }
+
+ public String getReturnType()
+ {
+ String result = null;
+ if (!isConstructor() && (method.getReturnType2() != null))
+ {
+ result = method.getReturnType2().toString();
}
- catch (Exception e)
+ return result;
+ }
+
+ public Method setReturnType(final Class<?> type)
+ {
+ return setReturnType(type.getSimpleName());
+ }
+
+ public Method setReturnType(final String type)
+ {
+ method.setReturnType2(ast.newSimpleType(ast.newSimpleName(type)));
+ return this;
+ }
+
+ public Method setReturnTypeVoid()
+ {
+ method.setReturnType2(null);
+ return this;
+ }
+
+ private MethodDeclaration getMethodDeclaration()
+ {
+ return method;
+ }
+
+ @Override
+ public String toString()
+ {
+ return method.toString();
+ }
+
+ @SuppressWarnings("unchecked")
+ private boolean hasModifier(final ModifierKeyword modifier)
+ {
+ boolean result = false;
+ List<Modifier> modifiers = method.modifiers();
+ for (Modifier m : modifiers)
{
- throw new RuntimeException("Could not add method: \"" +
- "\" to compilation unit: \"" + javaClass.getName() + "\"", e);
+ if (m.getKeyword() == modifier)
+ {
+ result = true;
+ }
}
+ return result;
}
+
+ @Override
+ public Object getInternal()
+ {
+ return method;
+ }
+
+ public void applyChanges()
+ {
+ parent.applyChanges();
+ }
}
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/MethodFinderVisitor.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/MethodFinderVisitor.java 2010-07-08 14:54:54 UTC (rev 13351)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/MethodFinderVisitor.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -1,3 +1,24 @@
+/*
+ * 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.grammar.java.ast;
import java.util.ArrayList;
@@ -9,6 +30,11 @@
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+/**
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
public class MethodFinderVisitor extends ASTVisitor
{
private final List<MethodDeclaration> methods = new ArrayList<MethodDeclaration>();
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java 2010-07-08 14:54:54 UTC (rev 13351)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -1,3 +1,24 @@
+/*
+ * 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.grammar.java.ast;
import java.util.ArrayList;
@@ -7,6 +28,11 @@
import org.eclipse.jdt.core.dom.ASTVisitor;
import org.eclipse.jdt.core.dom.TypeDeclaration;
+/**
+ *
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ *
+ */
public class TypeDeclarationFinderVisitor extends ASTVisitor
{
private final List<TypeDeclaration> types = new ArrayList<TypeDeclaration>();
Modified: sandbox/encore/core/src/main/java/org/jboss/encore/model/Mutable.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/model/Mutable.java 2010-07-08 14:54:54 UTC (rev 13351)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/model/Mutable.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -22,10 +22,16 @@
package org.jboss.encore.model;
/**
+ * Represents an object that queues changes before making final modifications to a resource.
+ *
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
- *
+ *
*/
public interface Mutable
{
-
+ /**
+ * Apply all changes made to this or other objects to which this may belong. (Apply all pending changes in the object
+ * graph.)
+ */
+ void applyChanges();
}
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-08 14:54:54 UTC (rev 13351)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-07-08 20:56:09 UTC (rev 13352)
@@ -1,71 +1,136 @@
+/*
+ * 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.grammar.java;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
import java.io.InputStream;
import java.net.URL;
import java.util.List;
import java.util.Map;
-import org.eclipse.jdt.core.dom.ImportDeclaration;
import org.junit.Before;
import org.junit.Test;
+/**
+ * @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
+ */
public class JavaClassTest
{
private InputStream stream;
+ private JavaClass javaClass;
@Before
public void reset()
{
stream = JavaClassTest.class
.getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
+ javaClass = new JavaClass(stream);
}
@Test
public void testParse() throws Exception
{
- JavaClass parser = new JavaClass(stream);
- List<ImportDeclaration> imports = parser.getImports();
-
- assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
+ List<Import> imports = javaClass.getImports();
+ assertEquals(URL.class.getName(), imports.get(0).getName());
}
@Test
public void testAddImport() throws Exception
{
- JavaClass parser = new JavaClass(stream);
- parser.addImport(List.class.getName());
- List<ImportDeclaration> imports = parser.getImports();
+ javaClass.addImport(List.class.getName());
+ List<Import> imports = javaClass.getImports();
assertEquals(2, imports.size());
- assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
- assertEquals(List.class.getName(), imports.get(1).getName().getFullyQualifiedName());
+ assertEquals(URL.class.getName(), imports.get(0).getName());
+ assertEquals(List.class.getName(), imports.get(1).getName());
}
@Test
public void testAddImportsClasses() throws Exception
{
- JavaClass parser = new JavaClass(stream);
-
- List<ImportDeclaration> imports = parser.getImports();
+ List<Import> imports = javaClass.getImports();
assertEquals(1, imports.size());
- parser.addImports(List.class, Map.class);
+ javaClass.addImports(List.class, Map.class);
- imports = parser.getImports();
+ imports = javaClass.getImports();
assertEquals(3, imports.size());
- assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
- assertEquals(List.class.getName(), imports.get(1).getName().getFullyQualifiedName());
- assertEquals(Map.class.getName(), imports.get(2).getName().getFullyQualifiedName());
+ assertEquals(Map.class.getName(), imports.get(2).getName());
}
@Test
public void testAddMethod() throws Exception
{
- JavaClass javaClass = new JavaClass(stream);
- javaClass.addMethod().name("testMethod").returnType(String.class).add();
+ javaClass.addMethod().setName("testMethod").setReturnTypeVoid().setBody("").applyChanges();
List<Method> methods = javaClass.getMethods();
assertEquals(3, methods.size());
+ assertNull(methods.get(2).getReturnType());
}
+ @Test
+ public void testAddMethodFromString() throws Exception
+ {
+ javaClass.addMethod("public URL rewriteURL(String pattern, String replacement) { return null; }")
+ .setPackagePrivate().applyChanges();
+ List<Method> methods = javaClass.getMethods();
+ assertEquals(3, methods.size());
+ assertEquals("URL", methods.get(2).getReturnType());
+ assertEquals("rewriteURL", methods.get(2).getName());
+
+ String body = methods.get(2).getBody();
+ assertEquals("return null;".replaceAll("\\s+", ""),
+ body.replaceAll("\\s+", ""));
+ }
+
+ @Test
+ public void testAddConstructor() throws Exception
+ {
+ javaClass.addMethod().setName("testMethod").setConstructor(true).setProtected().setReturnType(String.class)
+ .setBody("System.out.println(\"I am a constructor!\");").applyChanges();
+ List<Method> methods = javaClass.getMethods();
+ assertEquals(3, methods.size());
+ assertTrue(methods.get(2).isProtected());
+ assertTrue(methods.get(2).isConstructor());
+ assertNull(methods.get(2).getReturnType());
+ String body = methods.get(2).getBody();
+ assertEquals("System.out.println(\"I am a constructor!\");".replaceAll("\\s+", ""),
+ body.replaceAll("\\s+", ""));
+ }
+
+ @Test
+ public void testAddConstructorIngoresReturnTypeAndName() throws Exception
+ {
+ javaClass.addMethod().setName("testMethod").setConstructor(true).setPrivate().setReturnType(String.class)
+ .setBody("System.out.println(\"I am a constructor!\");").applyChanges();
+ List<Method> methods = javaClass.getMethods();
+ assertTrue(methods.get(2).isPrivate());
+ assertTrue(methods.get(2).isConstructor());
+ assertNull(methods.get(2).getReturnType());
+ assertEquals("MockClassFile", methods.get(2).getName());
+ String body = methods.get(2).getBody();
+ assertEquals("System.out.println(\"I am a constructor!\");".replaceAll("\\s+", ""),
+ body.replaceAll("\\s+", ""));
+ }
+
}
14 years, 5 months
Seam SVN: r13351 - in branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom: resources and 1 other directory.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2010-07-08 10:54:54 -0400 (Thu, 08 Jul 2010)
New Revision: 13351
Added:
branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/resources/jboss-seam-chatroom-hornetq-jms.xml
Modified:
branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/build.xml
branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/readme.txt
Log:
JBPAPP-4583
Modified: branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/build.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/build.xml 2010-07-08 14:19:10 UTC (rev 13350)
+++ branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/build.xml 2010-07-08 14:54:54 UTC (rev 13351)
@@ -13,6 +13,10 @@
<property name="facelets.lib" value="yes"/>
<property name="cache.lib" value="yes"/>
+ <condition property="example.service" value="jboss-seam-chatroom-hornetq-jms.xml" >
+ <isset property="hornetq" />
+ </condition>
+
<import file="../../build.xml"/>
</project>
Modified: branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/readme.txt
===================================================================
--- branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/readme.txt 2010-07-08 14:19:10 UTC (rev 13350)
+++ branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/readme.txt 2010-07-08 14:54:54 UTC (rev 13351)
@@ -4,4 +4,6 @@
This example shows using Seam Remoting to subscribe and publish messages to JMS.
It runs on JBoss AS as an EAR.
+To run the example on JBoss AS with HornetQ, set the hornetq property to true (i.e. ant deploy -Dhornetq=true)
+
example.name=chatroom
Added: branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/resources/jboss-seam-chatroom-hornetq-jms.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/resources/jboss-seam-chatroom-hornetq-jms.xml (rev 0)
+++ branches/enterprise/JBPAPP_5_0/examples/remoting/chatroom/resources/jboss-seam-chatroom-hornetq-jms.xml 2010-07-08 14:54:54 UTC (rev 13351)
@@ -0,0 +1,9 @@
+<configuration xmlns="urn:hornetq"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="urn:hornetq /schema/hornetq-jms.xsd">
+
+ <topic name="chatroomTopic">
+ <entry name="topic/chatroomTopic"/>
+ </topic>
+
+</configuration>
14 years, 5 months
Seam SVN: r13350 - branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2010-07-08 10:19:10 -0400 (Thu, 08 Jul 2010)
New Revision: 13350
Modified:
branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml
Log:
Check if the server is actually started
Modified: branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml 2010-07-08 14:18:14 UTC (rev 13349)
+++ branches/enterprise/JBPAPP_4_3_FP01/src/test/ftest/examples/build.xml 2010-07-08 14:19:10 UTC (rev 13350)
@@ -205,9 +205,14 @@
<jvmarg line="${jboss.jvm.arguments}" />
<arg line="-c ${jboss.domain} -b ${jboss.host}" />
</java>
- <waitfor maxwait="2" maxwaitunit="minute">
+ <waitfor maxwait="2" maxwaitunit="minute" timeoutproperty="timeout">
<socket server="localhost" port="8080" />
</waitfor>
+ <fail message="Server not started within 2 minutes.">
+ <condition>
+ <isset property="timeout" />
+ </condition>
+ </fail>
</target>
<target name="stop.container.jboss" if="run.container.per.suite">
14 years, 5 months
Seam SVN: r13349 - branches/enterprise/JBPAPP_5_0/src/test/ftest.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2010-07-08 10:18:14 -0400 (Thu, 08 Jul 2010)
New Revision: 13349
Modified:
branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties
Log:
minor
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties 2010-07-08 14:17:30 UTC (rev 13348)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/ftest.properties 2010-07-08 14:18:14 UTC (rev 13349)
@@ -54,7 +54,7 @@
# container settings
jboss5.profile=default
-jboss5.jvm.arguments=-Xms512m -Xmx1024m -XX:MaxPermSize=512m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.lang.ClassLoader.allowArraySyntax=true"
+jboss5.jvm.arguments=-Xms512m -Xmx1024m -XX:MaxPermSize=512m -Dorg.jboss.resolver.warning=true -Dsun.rmi.dgc.client.gcInterval=3600000 -Dsun.rmi.dgc.server.gcInterval=3600000 -Dsun.lang.ClassLoader.allowArraySyntax=true
run.container.per.suite=true
jboss.deployments.restart=10
14 years, 5 months
Seam SVN: r13348 - branches/enterprise/JBPAPP_5_0/src/test/ftest/examples.
by seam-commits@lists.jboss.org
Author: jharting
Date: 2010-07-08 10:17:30 -0400 (Thu, 08 Jul 2010)
New Revision: 13348
Modified:
branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
Log:
Check if the server is actually started
Modified: branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml
===================================================================
--- branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml 2010-07-08 02:52:40 UTC (rev 13347)
+++ branches/enterprise/JBPAPP_5_0/src/test/ftest/examples/build.xml 2010-07-08 14:17:30 UTC (rev 13348)
@@ -261,9 +261,14 @@
<jvmarg line="${container.jvm.arguments}" />
<arg line="-c ${jboss.domain} -b ${jboss.host}" />
</java>
- <waitfor maxwait="2" maxwaitunit="minute">
+ <waitfor maxwait="2" maxwaitunit="minute" timeoutproperty="timeout">
<socket server="localhost" port="8080" />
</waitfor>
+ <fail message="Server not started within 2 minutes.">
+ <condition>
+ <isset property="timeout" />
+ </condition>
+ </fail>
</target>
<target name="stop.container.jboss" depends="container.properties" >
14 years, 5 months
Seam SVN: r13347 - in sandbox/encore/core/src: main/java/org/jboss/encore/grammar/java/ast and 2 other directories.
by seam-commits@lists.jboss.org
Author: lincolnthree
Date: 2010-07-07 22:52:40 -0400 (Wed, 07 Jul 2010)
New Revision: 13347
Added:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java
Removed:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java
sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaParserTest.java
Modified:
sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java
sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java
Log:
Almost have adding methods working... very ugly code - do not mimic this...
Copied: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java (from rev 13341, sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java)
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaClass.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -0,0 +1,170 @@
+package org.jboss.encore.grammar.java;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import java.util.Stack;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.ASTParser;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+import org.eclipse.jdt.internal.compiler.util.Util;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.text.edits.UndoEdit;
+import org.jboss.encore.grammar.java.ast.MethodFinderVisitor;
+import org.jboss.encore.grammar.java.ast.TypeDeclarationFinderVisitor;
+
+public class JavaClass
+{
+ private Document document;
+
+ private final Stack<UndoEdit> undoStack = new Stack<UndoEdit>();
+
+ /**
+ * Parses and process the java source code as a compilation unit and the result it abstract syntax tree (AST)
+ * representation and this action uses the third edition of java Language Specification.
+ *
+ * @param source - the java source to be parsed (i.e. the char[] contains Java source).
+ * @return CompilationUnit Abstract syntax tree representation of a java source file.
+ */
+ public JavaClass(final InputStream inputStream)
+ {
+ try
+ {
+ char[] source = Util.getInputStreamAsCharArray(inputStream, inputStream.available(), "ISO8859_1");
+ document = new Document(new String(source));
+ }
+ catch (Exception e)
+ {
+ throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
+ }
+ }
+
+ public JavaClass(final char[] source)
+ {
+ document = new Document(new String(source));
+ }
+
+ public JavaClass(final String source)
+ {
+ this(source.toCharArray());
+ }
+
+ public CompilationUnit parse()
+ {
+ ASTParser parser = ASTParser.newParser(AST.JLS3);
+ parser.setSource(document.get().toCharArray());
+ parser.setResolveBindings(true);
+ parser.setKind(ASTParser.K_COMPILATION_UNIT);
+ CompilationUnit cu = (CompilationUnit) parser.createAST(null);
+ return cu;
+ }
+
+ public Method addMethod()
+ {
+ return new Method(this);
+ }
+
+ @SuppressWarnings("unchecked")
+ public JavaClass addImport(final String className)
+ {
+ CompilationUnit cu = parse();
+ try
+ {
+ AST ast = cu.getAST();
+ cu.recordModifications();
+ // ASTRewrite rewriter = ASTRewrite.create(ast);
+ // ListRewrite lrw = rewriter.getListRewrite(cu, CompilationUnit.IMPORTS_PROPERTY);
+
+ ImportDeclaration id = ast.newImportDeclaration();
+ id.setName(ast.newName(tokenizeClassName(className)));
+ cu.imports().add(id);
+ TextEdit edit = cu.rewrite(document, null);
+ UndoEdit undo = edit.apply(document);
+
+ // lrw.insertLast(id, null);
+ //
+ // TextEdit edits = rewriter.rewriteAST(document, null);
+ // UndoEdit undo = edits.apply(document);
+ undoStack.add(undo);
+
+ return this;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not add import: \"" + className +
+ "\" to compilation unit: \"" + "\"", e);
+ }
+ }
+
+ public void addImport(final Class<?> type)
+ {
+ addImport(type.getName());
+ }
+
+ public void addImports(final Class<?>... types)
+ {
+ for (Class<?> type : types)
+ {
+ addImport(type.getName());
+ }
+ }
+
+ private String[] tokenizeClassName(final String className)
+ {
+ String[] result = className.split("\\.");
+ return result;
+ }
+
+ public Stack<UndoEdit> getUndoStack()
+ {
+ return undoStack;
+ }
+
+ @SuppressWarnings("unchecked")
+ public List<ImportDeclaration> getImports()
+ {
+ CompilationUnit unit = parse();
+ List<ImportDeclaration> imports = unit.imports();
+ return Collections.unmodifiableList(imports);
+ }
+
+ public List<Method> getMethods()
+ {
+ List<Method> result = new ArrayList<Method>();
+
+ CompilationUnit unit = parse();
+ MethodFinderVisitor methodFinderVisitor = new MethodFinderVisitor();
+ unit.accept(methodFinderVisitor);
+
+ List<MethodDeclaration> methods = methodFinderVisitor.getMethods();
+ for (MethodDeclaration methodDeclaration : methods)
+ {
+ result.add(new Method(this, methodDeclaration));
+ }
+ return result;
+ }
+
+ public TypeDeclaration getTypeDeclaration()
+ {
+ CompilationUnit unit = parse();
+ TypeDeclarationFinderVisitor typeDeclarationFinder = new TypeDeclarationFinderVisitor();
+ unit.accept(typeDeclarationFinder);
+ return typeDeclarationFinder.getTypeDeclarations().get(0);
+ }
+
+ public Document getDocument()
+ {
+ return document;
+ }
+
+ public String getName()
+ {
+ return getTypeDeclaration().getName().getIdentifier();
+ }
+}
Deleted: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java 2010-07-08 02:50:23 UTC (rev 13346)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/JavaParser.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -1,118 +0,0 @@
-package org.jboss.encore.grammar.java;
-
-import java.io.InputStream;
-import java.util.Collections;
-import java.util.List;
-import java.util.Stack;
-
-import org.eclipse.jdt.core.dom.AST;
-import org.eclipse.jdt.core.dom.ASTParser;
-import org.eclipse.jdt.core.dom.CompilationUnit;
-import org.eclipse.jdt.core.dom.ImportDeclaration;
-import org.eclipse.jdt.core.dom.rewrite.ASTRewrite;
-import org.eclipse.jdt.core.dom.rewrite.ListRewrite;
-import org.eclipse.jdt.internal.compiler.util.Util;
-import org.eclipse.jface.text.Document;
-import org.eclipse.text.edits.TextEdit;
-import org.eclipse.text.edits.UndoEdit;
-
-public class JavaParser
-{
- private Document document;
-
- private final Stack<UndoEdit> undoStack = new Stack<UndoEdit>();
-
- /**
- * Parses and process the java source code as a compilation unit and the result it abstract syntax tree (AST)
- * representation and this action uses the third edition of java Language Specification.
- *
- * @param source - the java source to be parsed (i.e. the char[] contains Java source).
- * @return CompilationUnit Abstract syntax tree representation of a java source file.
- */
- public JavaParser(final InputStream inputStream)
- {
- try
- {
- char[] source = Util.getInputStreamAsCharArray(inputStream, inputStream.available(), "ISO8859_1");
- document = new Document(new String(source));
- }
- catch (Exception e)
- {
- throw new IllegalArgumentException("InputStream must be a parsable java file: ", e);
- }
- }
-
- public JavaParser(final char[] source)
- {
- document = new Document(new String(source));
- }
-
- public CompilationUnit parse()
- {
- ASTParser parser = ASTParser.newParser(AST.JLS3);
- parser.setSource(document.get().toCharArray());
- parser.setResolveBindings(true);
- parser.setKind(ASTParser.K_COMPILATION_UNIT);
- CompilationUnit cu = (CompilationUnit) parser.createAST(null);
- return cu;
- }
-
- public JavaParser addImport(final String className)
- {
- CompilationUnit cu = parse();
- try
- {
- AST ast = cu.getAST();
- ASTRewrite rewriter = ASTRewrite.create(ast);
- ListRewrite lrw = rewriter.getListRewrite(cu, CompilationUnit.IMPORTS_PROPERTY);
-
- ImportDeclaration id = ast.newImportDeclaration();
- id.setName(ast.newName(tokenizeClassName(className)));
-
- lrw.insertLast(id, null);
-
- TextEdit edits = rewriter.rewriteAST(document, null);
- UndoEdit undo = edits.apply(document);
- undoStack.add(undo);
-
- return this;
- }
- catch (Exception e)
- {
- throw new RuntimeException("Could not add import: \"" + className +
- "\" to compilation unit: \"" + "\"", e);
- }
- }
-
- public void addImport(final Class<?> type)
- {
- addImport(type.getName());
- }
-
- public void addImports(final Class<?>... types)
- {
- for (Class<?> type : types)
- {
- addImport(type.getName());
- }
- }
-
- private String[] tokenizeClassName(final String className)
- {
- String[] result = className.split("\\.");
- return result;
- }
-
- public Stack<UndoEdit> getUndoStack()
- {
- return undoStack;
- }
-
- @SuppressWarnings("unchecked")
- public List<ImportDeclaration> getImports()
- {
- CompilationUnit unit = parse();
- List<ImportDeclaration> imports = unit.imports();
- return Collections.unmodifiableList(imports);
- }
-}
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-08 02:50:23 UTC (rev 13346)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/Method.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -21,11 +21,102 @@
*/
package org.jboss.encore.grammar.java;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.AST;
+import org.eclipse.jdt.core.dom.Block;
+import org.eclipse.jdt.core.dom.CompilationUnit;
+import org.eclipse.jdt.core.dom.MethodDeclaration;
+import org.eclipse.jface.text.Document;
+import org.eclipse.text.edits.TextEdit;
+import org.eclipse.text.edits.UndoEdit;
+
/**
* @author <a href="mailto:lincolnbaxter@gmail.com">Lincoln Baxter, III</a>
*
*/
public class Method
{
+ private final JavaClass javaClass;
+ private final AST ast;
+ private final CompilationUnit cu;
+ private final Document document;
+ private MethodDeclaration method;
+ private String body;
+ public Method(final JavaClass javaClass)
+ {
+ this.javaClass = javaClass;
+ cu = javaClass.parse();
+ cu.recordModifications();
+ document = javaClass.getDocument();
+ ast = cu.getAST();
+ method = ast.newMethodDeclaration();
+ method.setConstructor(false);
+ }
+
+ public Method(final JavaClass javaClass, final MethodDeclaration methodDeclaration)
+ {
+ this(javaClass);
+ method = methodDeclaration;
+ }
+
+ public Method name(final String name)
+ {
+ method.setName(ast.newSimpleName(name));
+ return this;
+ }
+
+ public Method constructor(final boolean isConstructor)
+ {
+ method.setConstructor(isConstructor);
+ return this;
+ }
+
+ public Method returnType(final Class<?> type)
+ {
+ return returnType(type.getSimpleName());
+ }
+
+ public Method returnType(final String type)
+ {
+ method.setReturnType2(ast.newSimpleType(ast.newSimpleName(type)));
+ return this;
+ }
+
+ public Method body(final String body)
+ {
+ this.body = body;
+ String stub = "public class Stub { public void method() {" + body + "} }";
+ JavaClass temp = new JavaClass(stub);
+ List<Method> methods = temp.getMethods();
+ Block block = methods.get(0).getMethodDeclaration().getBody();
+ method.setBody(block);
+ return this;
+ }
+
+ private MethodDeclaration getMethodDeclaration()
+ {
+ return method;
+ }
+
+ @SuppressWarnings("unchecked")
+ public JavaClass add()
+ {
+ try
+ {
+ boolean add = javaClass.getTypeDeclaration().bodyDeclarations().add(method);
+
+ TextEdit edit = cu.rewrite(document, null);
+ UndoEdit undo = edit.apply(document);
+
+ javaClass.getUndoStack().add(undo);
+ return javaClass;
+ }
+ catch (Exception e)
+ {
+ throw new RuntimeException("Could not add method: \"" +
+ "\" to compilation unit: \"" + javaClass.getName() + "\"", e);
+ }
+ }
}
Added: sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java
===================================================================
--- sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java (rev 0)
+++ sandbox/encore/core/src/main/java/org/jboss/encore/grammar/java/ast/TypeDeclarationFinderVisitor.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -0,0 +1,26 @@
+package org.jboss.encore.grammar.java.ast;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.eclipse.jdt.core.dom.ASTVisitor;
+import org.eclipse.jdt.core.dom.TypeDeclaration;
+
+public class TypeDeclarationFinderVisitor extends ASTVisitor
+{
+ private final List<TypeDeclaration> types = new ArrayList<TypeDeclaration>();
+
+ @Override
+ public boolean visit(final TypeDeclaration node)
+ {
+ types.addAll(Arrays.asList(node));
+ return super.visit(node);
+ }
+
+ public List<TypeDeclaration> getTypeDeclarations()
+ {
+ return types;
+ }
+
+}
\ No newline at end of file
Copied: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java (from rev 13341, sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaParserTest.java)
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java (rev 0)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaClassTest.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -0,0 +1,71 @@
+package org.jboss.encore.grammar.java;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.InputStream;
+import java.net.URL;
+import java.util.List;
+import java.util.Map;
+
+import org.eclipse.jdt.core.dom.ImportDeclaration;
+import org.junit.Before;
+import org.junit.Test;
+
+public class JavaClassTest
+{
+ private InputStream stream;
+
+ @Before
+ public void reset()
+ {
+ stream = JavaClassTest.class
+ .getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
+ }
+
+ @Test
+ public void testParse() throws Exception
+ {
+ JavaClass parser = new JavaClass(stream);
+ List<ImportDeclaration> imports = parser.getImports();
+
+ assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
+ }
+
+ @Test
+ public void testAddImport() throws Exception
+ {
+ JavaClass parser = new JavaClass(stream);
+ parser.addImport(List.class.getName());
+ List<ImportDeclaration> imports = parser.getImports();
+ assertEquals(2, imports.size());
+ assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
+ assertEquals(List.class.getName(), imports.get(1).getName().getFullyQualifiedName());
+ }
+
+ @Test
+ public void testAddImportsClasses() throws Exception
+ {
+ JavaClass parser = new JavaClass(stream);
+
+ List<ImportDeclaration> imports = parser.getImports();
+ assertEquals(1, imports.size());
+
+ parser.addImports(List.class, Map.class);
+
+ imports = parser.getImports();
+ assertEquals(3, imports.size());
+ assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
+ assertEquals(List.class.getName(), imports.get(1).getName().getFullyQualifiedName());
+ assertEquals(Map.class.getName(), imports.get(2).getName().getFullyQualifiedName());
+ }
+
+ @Test
+ public void testAddMethod() throws Exception
+ {
+ JavaClass javaClass = new JavaClass(stream);
+ javaClass.addMethod().name("testMethod").returnType(String.class).add();
+ List<Method> methods = javaClass.getMethods();
+ assertEquals(3, methods.size());
+ }
+
+}
Deleted: sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaParserTest.java
===================================================================
--- sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaParserTest.java 2010-07-08 02:50:23 UTC (rev 13346)
+++ sandbox/encore/core/src/test/java/org/jboss/encore/grammar/java/JavaParserTest.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -1,62 +0,0 @@
-package org.jboss.encore.grammar.java;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.InputStream;
-import java.net.URL;
-import java.util.List;
-import java.util.Map;
-
-import org.eclipse.jdt.core.dom.ImportDeclaration;
-import org.junit.Before;
-import org.junit.Test;
-
-public class JavaParserTest
-{
- private InputStream stream;
-
- @Before
- public void reset()
- {
- stream = JavaParserTest.class
- .getResourceAsStream("/org/jboss/encore/grammar/java/MockClassFile.java");
- }
-
- @Test
- public void testParse() throws Exception
- {
- JavaParser parser = new JavaParser(stream);
- List<ImportDeclaration> imports = parser.getImports();
-
- assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
- }
-
- @Test
- public void testAddImport() throws Exception
- {
- JavaParser parser = new JavaParser(stream);
- parser.addImport(List.class.getName());
- List<ImportDeclaration> imports = parser.getImports();
- assertEquals(2, imports.size());
- assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
- assertEquals(List.class.getName(), imports.get(1).getName().getFullyQualifiedName());
- }
-
- @Test
- public void testAddImportsClasses() throws Exception
- {
- JavaParser parser = new JavaParser(stream);
-
- List<ImportDeclaration> imports = parser.getImports();
- assertEquals(1, imports.size());
-
- parser.addImports(List.class, Map.class);
-
- imports = parser.getImports();
- assertEquals(3, imports.size());
- assertEquals(URL.class.getName(), imports.get(0).getName().getFullyQualifiedName());
- assertEquals(List.class.getName(), imports.get(1).getName().getFullyQualifiedName());
- assertEquals(Map.class.getName(), imports.get(2).getName().getFullyQualifiedName());
- }
-
-}
Modified: sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java
===================================================================
--- sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java 2010-07-08 02:50:23 UTC (rev 13346)
+++ sandbox/encore/core/src/test/resources/org/jboss/encore/grammar/java/MockClassFile.java 2010-07-08 02:52:40 UTC (rev 13347)
@@ -11,10 +11,6 @@
{
}
- public void method()
- {
- }
-
public String valueOf(URL url)
{
return url.getPath();
14 years, 5 months
Seam SVN: r13346 - /.
by seam-commits@lists.jboss.org
Author: dan.j.allen
Date: 2010-07-07 22:50:23 -0400 (Wed, 07 Jul 2010)
New Revision: 13346
Modified:
about.txt
Log:
auxiliary folder definitions
Modified: about.txt
===================================================================
--- about.txt 2010-07-08 02:46:39 UTC (rev 13345)
+++ about.txt 2010-07-08 02:50:23 UTC (rev 13346)
@@ -24,3 +24,10 @@
sandbox/ Prototypes of Seam 3 modules, examples or other project ideas
Seam 3 has bundled releases, which is assembled from the dist root.
+
+Other
+=====
+There are several auxilary roots not part of the main Seam build.
+
+admin/ Ignore; Restricted
+maven-plugins/ Seam reference guide DocBook styles and Seam 2 wicket intrumentation
14 years, 5 months