You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tomee.apache.org by rm...@apache.org on 2012/01/18 14:33:27 UTC
svn commit: r1232875 - in /openejb/trunk/openejb:
container/openejb-core/src/main/java/org/apache/openejb/table/
container/openejb-core/src/main/java/org/apache/openejb/util/helper/
osgi/openejb-karaf-commands/ osgi/openejb-karaf-commands/src/main/java...
Author: rmannibucau
Date: Wed Jan 18 13:33:26 2012
New Revision: 1232875
URL: http://svn.apache.org/viewvc?rev=1232875&view=rev
Log:
adding list command to ssh module
Added:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/helper/
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/helper/CommandHelper.java
Modified:
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Line.java
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Lines.java
openejb/trunk/openejb/osgi/openejb-karaf-commands/pom.xml
openejb/trunk/openejb/osgi/openejb-karaf-commands/src/main/java/org/apache/openejb/karaf/command/ListEJBs.java
openejb/trunk/openejb/server/openejb-ssh/src/main/java/org/apache/openejb/server/ssh/OpenEJBCommands.java
openejb/trunk/openejb/server/openejb-ssh/src/test/java/org/apache/openejb/server/ssh/SSHServerTest.java
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Line.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Line.java?rev=1232875&r1=1232874&r2=1232875&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Line.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Line.java Wed Jan 18 13:33:26 2012
@@ -26,6 +26,7 @@ public class Line {
public static final char EMPTY_CHAR = ' ';
private String[] columns;
+ private String cr = System.getProperty("line.separator");
public Line(String... columns) {
this.columns = columns;
@@ -75,7 +76,11 @@ public class Line {
printLine(out, sep.toString());
}
- private static void printLine(final PrintStream out, final String s) {
- out.println(s);
+ private void printLine(final PrintStream out, final String s) {
+ out.print(s + cr);
+ }
+
+ public void setCr(final String cr) {
+ this.cr = cr;
}
}
Modified: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Lines.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Lines.java?rev=1232875&r1=1232874&r2=1232875&view=diff
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Lines.java (original)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/table/Lines.java Wed Jan 18 13:33:26 2012
@@ -24,11 +24,17 @@ import java.util.List;
public class Lines {
private List<Line> lines = new ArrayList<Line>();
+ private String cr = System.getProperty("line.separator");
+
+ public Lines(String cr) {
+ this.cr = cr;
+ }
public void add(Line line) {
if (!lines.isEmpty() && lines.iterator().next().getColumns().length != line.getColumns().length) {
throw new IllegalArgumentException("columns should have all the same size");
}
+ line.setCr(cr);
lines.add(line);
}
@@ -63,4 +69,8 @@ public class Lines {
}
return max;
}
+
+ public List<Line> getLines() {
+ return lines;
+ }
}
Added: openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/helper/CommandHelper.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/helper/CommandHelper.java?rev=1232875&view=auto
==============================================================================
--- openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/helper/CommandHelper.java (added)
+++ openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/util/helper/CommandHelper.java Wed Jan 18 13:33:26 2012
@@ -0,0 +1,65 @@
+package org.apache.openejb.util.helper;
+
+import org.apache.openejb.BeanContext;
+import org.apache.openejb.BeanType;
+import org.apache.openejb.loader.SystemInstance;
+import org.apache.openejb.spi.ContainerSystem;
+import org.apache.openejb.table.Line;
+import org.apache.openejb.table.Lines;
+
+import java.util.Arrays;
+
+public class CommandHelper {
+ private CommandHelper() {
+ // no-op
+ }
+
+ public static Lines listEJBs() throws Exception {
+ return listEJBs(System.getProperty("line.separator"));
+ }
+
+ public static Lines listEJBs(final String cr) throws Exception {
+ final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
+ Lines lines = new Lines(cr);
+ lines.add(new Line("Name", "Class", "Interface Type", "Bean Type"));
+ for (BeanContext bc : cs.deployments()) {
+ if (BeanContext.Comp.class.equals(bc.getBeanClass())) {
+ continue;
+ }
+
+ lines.add(new Line(bc.getEjbName(), bc.getBeanClass().getName(), getType(bc), componentType(bc.getComponentType())));
+ }
+
+ return lines;
+ }
+
+ private static String componentType(final BeanType componentType) {
+ if (componentType == null) {
+ return "unknown";
+ }
+ return componentType.name();
+ }
+
+ private static String getType(final BeanContext bc) {
+ boolean empty = true;
+ final StringBuilder sb = new StringBuilder();
+ if (bc.isLocalbean()) {
+ sb.append("LocalBean[").append(bc.getBeanClass()).append("]");
+ empty = false;
+ }
+ if (bc.getBusinessLocalInterface() != null) {
+ if (!empty) {
+ sb.append(", ");
+ }
+ sb.append("Local").append(Arrays.asList(bc.getBusinessLocalInterfaces()));
+ empty = false;
+ }
+ if (bc.getBusinessRemoteInterface() != null) {
+ if (!empty) {
+ sb.append(", ");
+ }
+ sb.append("Remote").append(Arrays.asList(bc.getBusinessRemoteInterfaces()));
+ }
+ return sb.toString();
+ }
+}
Modified: openejb/trunk/openejb/osgi/openejb-karaf-commands/pom.xml
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-karaf-commands/pom.xml?rev=1232875&r1=1232874&r2=1232875&view=diff
==============================================================================
--- openejb/trunk/openejb/osgi/openejb-karaf-commands/pom.xml (original)
+++ openejb/trunk/openejb/osgi/openejb-karaf-commands/pom.xml Wed Jan 18 13:33:26 2012
@@ -42,6 +42,7 @@
org.apache.karaf.shell.console.completer;version="[2.2,3)",
org.apache.openejb.loader;version="[4.0,5.0)",
org.apache.openejb.table;version="[4.0,5.0)",
+ org.apache.openejb.util.helper;version="[4.0,5.0)",
org.apache.openejb.spi;version="[4.0,5.0)",
org.apache.openejb.core.osgi.impl;version="[4.0,5.0)",
org.apache.openejb.assembler.classic;version="[4.0,5.0)",
Modified: openejb/trunk/openejb/osgi/openejb-karaf-commands/src/main/java/org/apache/openejb/karaf/command/ListEJBs.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/osgi/openejb-karaf-commands/src/main/java/org/apache/openejb/karaf/command/ListEJBs.java?rev=1232875&r1=1232874&r2=1232875&view=diff
==============================================================================
--- openejb/trunk/openejb/osgi/openejb-karaf-commands/src/main/java/org/apache/openejb/karaf/command/ListEJBs.java (original)
+++ openejb/trunk/openejb/osgi/openejb-karaf-commands/src/main/java/org/apache/openejb/karaf/command/ListEJBs.java Wed Jan 18 13:33:26 2012
@@ -19,62 +19,13 @@ package org.apache.openejb.karaf.command
import org.apache.felix.gogo.commands.Command;
import org.apache.karaf.shell.console.OsgiCommandSupport;
-import org.apache.openejb.BeanContext;
-import org.apache.openejb.BeanType;
-import org.apache.openejb.table.Line;
-import org.apache.openejb.table.Lines;
-import org.apache.openejb.loader.SystemInstance;
-import org.apache.openejb.spi.ContainerSystem;
-
-import java.util.Arrays;
+import org.apache.openejb.util.helper.CommandHelper;
@Command(scope = "openejb", name = "list", description = "Lists all EJBs.")
public class ListEJBs extends OsgiCommandSupport {
@Override
protected Object doExecute() throws Exception {
- final ContainerSystem cs = SystemInstance.get().getComponent(ContainerSystem.class);
- Lines lines = new Lines();
- lines.add(new Line("Name", "Class", "Interface Type", "Bean Type"));
- for (BeanContext bc : cs.deployments()) {
- if (BeanContext.Comp.class.equals(bc.getBeanClass())) {
- continue;
- }
-
- lines.add(new Line(bc.getEjbName(), bc.getBeanClass().getName(), getType(bc), componentType(bc.getComponentType())));
- }
-
- lines.print(System.out);
-
+ CommandHelper.listEJBs().print(System.out);
return null;
}
-
- private static String componentType(final BeanType componentType) {
- if (componentType == null) {
- return "unknown";
- }
- return componentType.name();
- }
-
- private static String getType(final BeanContext bc) {
- boolean empty = true;
- final StringBuilder sb = new StringBuilder();
- if (bc.isLocalbean()) {
- sb.append("LocalBean[").append(bc.getBeanClass()).append("]");
- empty = false;
- }
- if (bc.getBusinessLocalInterface() != null) {
- if (!empty) {
- sb.append(", ");
- }
- sb.append("Local").append(Arrays.asList(bc.getBusinessLocalInterfaces()));
- empty = false;
- }
- if (bc.getBusinessRemoteInterface() != null) {
- if (!empty) {
- sb.append(", ");
- }
- sb.append("Remote").append(Arrays.asList(bc.getBusinessRemoteInterfaces()));
- }
- return sb.toString();
- }
}
Modified: openejb/trunk/openejb/server/openejb-ssh/src/main/java/org/apache/openejb/server/ssh/OpenEJBCommands.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ssh/src/main/java/org/apache/openejb/server/ssh/OpenEJBCommands.java?rev=1232875&r1=1232874&r2=1232875&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-ssh/src/main/java/org/apache/openejb/server/ssh/OpenEJBCommands.java (original)
+++ openejb/trunk/openejb/server/openejb-ssh/src/main/java/org/apache/openejb/server/ssh/OpenEJBCommands.java Wed Jan 18 13:33:26 2012
@@ -4,6 +4,7 @@ import jline.ConsoleReader;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;
import org.apache.openejb.server.groovy.OpenEJBGroovyShell;
+import org.apache.openejb.util.helper.CommandHelper;
import org.apache.sshd.server.Command;
import org.apache.sshd.server.Environment;
import org.apache.sshd.server.ExitCallback;
@@ -12,14 +13,17 @@ import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
+import java.io.PrintStream;
import java.util.Collection;
public class OpenEJBCommands implements Command, Runnable {
public static final String EXIT_COMMAND = "exit";
private static final String GROOVY_PREFIX = "G ";
+ private static final String LIST_CMD = "list";
private static final String WELCOME = "Welcome on your $bind:$port $name server";
public static final String LINE_SEP = "\r\n"; // don't use line.separator (sshd use this one)
public static final String OS_LINE_SEP = System.getProperty("line.separator");
+ private static final String NAME;
public static final String PROMPT = "openejb> ";
static {
@@ -28,21 +32,32 @@ public class OpenEJBCommands implements
// just to force the loading of this class with the set line.separator
// because ConsoleReader.CR is a constant and we need sometimes another value
// not a big issue but keeping this as a workaround
- final ConsoleReader reader = new ConsoleReader();
+ new ConsoleReader();
} catch (IOException ignored) {
// no-op
}
System.setProperty("line.separator", OS_LINE_SEP);
+
+ String name = "OpenEJB";
+ try {
+ OpenEJBCommands.class.getClassLoader().loadClass("org.apache.tomee.loader.TomcatHook");
+ name = "TomEE";
+ } catch (ClassNotFoundException cnfe) {
+ // ignored, we are using a simple OpenEJB server
+ }
+ NAME = name;
}
private OpenEJBGroovyShell shell;
private OutputStreamWriter serr;
private OutputStreamWriter sout;
+ private OutputStream out;
private ExitCallback cbk;
private InputStream sin;
private String bind;
private int port;
+
public OpenEJBCommands(String bind, int port) {
this.bind = bind;
this.port = port;
@@ -55,6 +70,7 @@ public class OpenEJBCommands implements
@Override
public void setOutputStream(OutputStream out) {
+ this.out = out;
sout = new OutputStreamWriter(out);
}
@@ -86,19 +102,11 @@ public class OpenEJBCommands implements
final ConsoleReader reader = new ConsoleReader(sin, sout);
// TODO : add completers with method names...?
- String name = "OpenEJB";
- try {
- getClass().getClassLoader().loadClass("org.apache.tomee.loader.TomcatHook");
- name = "TomEE";
- } catch (ClassNotFoundException cnfe) {
- // ignored, we are using a simple OpenEJB server
- }
-
String line;
write(sout, WELCOME // simple replace for now, if it is mandatory we could bring velocity to do it
.replace("$bind", bind)
.replace("$port", Integer.toString(port))
- .replace("$name", name));
+ .replace("$name", NAME));
while ((line = reader.readLine(PROMPT)) != null) {
if (EXIT_COMMAND.equals(line)) {
break;
@@ -106,10 +114,12 @@ public class OpenEJBCommands implements
if (line.startsWith(GROOVY_PREFIX)) {
try {
- write(sout, result(line));
+ write(sout, result(line.substring(GROOVY_PREFIX.length())));
} catch (SshRuntimeException sshEx) {
write((Exception) sshEx.getCause());
}
+ } else if (LIST_CMD.equals(line)) {
+ list();
} else {
write(sout, "sorry i don't understand '" + line + "'");
}
@@ -121,6 +131,14 @@ public class OpenEJBCommands implements
}
}
+ private void list() {
+ try {
+ CommandHelper.listEJBs(LINE_SEP).print(new PrintStream(out));
+ } catch (Exception e) {
+ write(e);
+ }
+ }
+
private static void write(final OutputStreamWriter writer, final String s) {
for (String l : s.split(LINE_SEP)) {
try {
Modified: openejb/trunk/openejb/server/openejb-ssh/src/test/java/org/apache/openejb/server/ssh/SSHServerTest.java
URL: http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-ssh/src/test/java/org/apache/openejb/server/ssh/SSHServerTest.java?rev=1232875&r1=1232874&r2=1232875&view=diff
==============================================================================
--- openejb/trunk/openejb/server/openejb-ssh/src/test/java/org/apache/openejb/server/ssh/SSHServerTest.java (original)
+++ openejb/trunk/openejb/server/openejb-ssh/src/test/java/org/apache/openejb/server/ssh/SSHServerTest.java Wed Jan 18 13:33:26 2012
@@ -24,6 +24,7 @@ import org.junit.Test;
import javax.ejb.embeddable.EJBContainer;
import java.io.File;
import java.util.HashMap;
+import java.util.concurrent.CountDownLatch;
public class SSHServerTest {
private static EJBContainer container;