You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by ni...@apache.org on 2004/02/14 05:17:23 UTC

cvs commit: avalon-sandbox/console/src/org/apache/avalon/excalibur/console CommandInterpreter.java ConsoleCommand.java ConsoleImpl.java DummyCmd.java EchoCmd.java ExitCmd.java HelpCmd.java LoginCmd.java LoginException.java TestCaseEchoCmd.java TestCaseHelpCmd.java ThreadCmd.java

niclas      2004/02/13 20:17:23

  Added:       console  build.properties build.xml buildSupport.xml
               console/includes console console.MF console.exc console.inc
               console/lib log4j-1.2.7.jar
               console/src/org/apache/avalon/excalibur/console
                        CommandInterpreter.java ConsoleCommand.java
                        ConsoleImpl.java DummyCmd.java EchoCmd.java
                        ExitCmd.java HelpCmd.java LoginCmd.java
                        LoginException.java TestCaseEchoCmd.java
                        TestCaseHelpCmd.java ThreadCmd.java
  Log:
  A small utility to get console access via telnet.
  
  Revision  Changes    Path
  1.1                  avalon-sandbox/console/build.properties
  
  Index: build.properties
  ===================================================================
  project.name=avalon-console
  project.Name=Avalon Console
  year=2004
  debug=on
  src.dir=./src
  production.dir=./production
  resources.dir=./resources
  includes.dir=./includes
  lib.dir=./lib
  build.dir=./build
  build.src=./build/src
  build.includes=./build/includes
  build.dest=./build/classes
  build.lib=./build/lib
  build.dist=./build/dist
  build.install=./build/dist/install
  build.upload=./build/dist/upload
  build.versions=./build/versions
  build.docs=./build/docs
  build.apidocs=./build/docs/apidocs/
  testsuite.report=./build/docs/unittest/
  testsuite.cases=./build/docs/unittest/testcases/
  
  
  
  1.1                  avalon-sandbox/console/build.xml
  
  Index: build.xml
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <project name="console" default="all" basedir=".">
    <target name="init" >
      <tstamp />
      <property name="subsystem.name" value="console" />
      <property name="base.dir" value="${basedir}" />
      <property file="build.properties" />
    </target>
  
    <target name="prepare" depends="init" >
      <ant dir="." antfile="buildSupport.xml" target="prepare" />
    </target>
  
    <!-- =================================================================== -->
    <!-- Compiles the source tree                                            -->
    <!-- =================================================================== -->
    <target name="compile" depends="prepare">
      <javac srcdir="${build.src}"
             destdir="${build.dest}"
             debug="${debug}"
      >
        <classpath>
          <pathelement path="${build.lib}/log4j-1.2.7.jar" />
        </classpath>
      </javac>
    </target>
  
    <!-- ====================== -->
    <!-- Builds the Service JAR -->
    <!-- ====================== -->
    <target name="jar" depends="compile">
      <jar jarfile="${build.lib}/${subsystem.name}.jar"
           includesfile="${includes.dir}/${subsystem.name}.inc"
           excludesfile="${includes.dir}/${subsystem.name}.exc"
           manifest="${build.includes}/${subsystem.name}.MF"
           basedir="${build.dest}"/>
    </target>
  
    <target name="all" depends="jar" >
    </target>
    
    <target name="clean" depends="init" >
      <ant dir="." antFile="buildSupport.xml" target="clean" />
    </target>
  </project>
  
  
  
  1.1                  avalon-sandbox/console/buildSupport.xml
  
  Index: buildSupport.xml
  ===================================================================
  <?xml version="1.0" encoding="utf-8"?>
  
  <!-- Includes sub targets for code management -->
  
  <project name="buildSupport" default="" >
  
    <!-- Sets up the build environment.
         Input
           basedir    Set to the subsystem directory name
    -->
    <target name="prepare" >
      <echo message="Building ${subsystem.name} in ${base.dir}" />
      <!-- create directories -->
      <mkdir dir="${base.dir}/${build.dir}"/>
      <mkdir dir="${base.dir}/${build.src}"/>
      <mkdir dir="${base.dir}/${build.dest}"/>
      <mkdir dir="${base.dir}/${build.dist}"/>
      <mkdir dir="${base.dir}/${build.lib}"/>
      <mkdir dir="${base.dir}/${build.dist}/output"/>
      <mkdir dir="${base.dir}/${build.install}"/>
      <mkdir dir="${base.dir}/${build.install}/lib"/>
      <mkdir dir="${base.dir}/${build.upload}"/>
      <mkdir dir="${base.dir}/${build.versions}"/>
      <mkdir dir="${base.dir}/${build.docs}"/>
      <mkdir dir="${base.dir}/${build.apidocs}"/>
      <mkdir dir="${base.dir}/${testsuite.cases}"/>
      <mkdir dir="${base.dir}/${testsuite.report}"/>
  
      <available property="production-available"
                 file="${base.dir}/${production.dir}"
                 type="dir"
      />
  
      <available property="includes-available"
                 file="${base.dir}/${includes.dir}"
                 type="dir"
      />
  
      <available property="resources-available"
                 file="${base.dir}/${resources.dir}"
                 type="dir"
      />
  
      <available property="src-available"
                 file="${base.dir}/${src.dir}"
                 type="dir"
      />
  
      <available property="lib-available"
                 file="${base.dir}/${lib.dir}"
                 type="dir"
      />
  
      <antcall target="copy-production" />
      <antcall target="copy-src" />
      <antcall target="copy-lib" />
      <antcall target="copy-resources" />
      <antcall target="copy-includes" >
        <param name="generation" value="1" />
        <param name="edition" value="0" />
        <param name="revision" value="0" />
        <param name="branch" value="alpha" />
        <param name="version" value="1.0-alpha.1" />
      </antcall>
    </target>
  
    <target name="copy-production" if="production-available" >
        <!-- copy production files -->
      <copy todir="${base.dir}/${build.install}">
        <fileset dir="${base.dir}/${production.dir}" />
      </copy>
    </target>
  
    <target name="copy-resources" if="resources-available" >
      <!-- copy resource files -->
      <copy todir="${base.dir}/${build.dest}">
        <fileset dir="${base.dir}/${resources.dir}" />
      </copy>
    </target>
    
    <target name="copy-lib" if="lib-available" >
      <!-- copy lib files -->
      <copy todir="${base.dir}/${build.lib}">
        <fileset dir="${base.dir}/${lib.dir}" />
      </copy>
    </target>
  
    <target name="copy-includes" if="includes-available" >
      <tstamp>
        <format property="build.time"
                pattern="yyyy-dd-MM HH:mm zz"
                locale="kj"
        />
      </tstamp>
  
      <filter token="GENERATION" value="${generation}" />
      <filter token="EDITION" value="${edition}" />
      <filter token="REVISION" value="${revision}" />
      <filter token="BRANCH" value="${branch}" />
      <filter token="VERSION" value="${version}" />
      <filter token="BUILDTIME" value="${build.time}" />
  
      <!-- copy includes files -->
      <copy todir="${base.dir}/${build.includes}" filtering="true">
        <fileset dir="${base.dir}/${includes.dir}" />
      </copy>
  
    </target>
  
    <target name="copy-src" if="src-available" >
      <!-- copy src files -->
      <copy todir="${base.dir}/${build.src}" >
        <fileset dir="${base.dir}/${src.dir}" />
      </copy>
    </target>
  
    <target name="clean" >
      <delete includeEmptyDirs="true" failonerror="false" >
        <fileset dir="${base.dir}/${build.dir}/" >
          <include name="**" />
        </fileset>
      </delete>
    </target>
  </project>
  
  
  
  1.1                  avalon-sandbox/console/includes/console
  
  Index: console
  ===================================================================
  <?xml version="1.0" ?>
  
  <Edition Status="alpha" >
      <Name>console-service</Name>
      <Generation>@VERSION@</Generation>
      <Resources>
          <Resource>
              <Name>console-service</Name>
              <Generation>@VERSION@</Generation>
          </Resource>
          <Resource>
              <Name>labzone-server</Name>
              <Generation>@LABZONE-SERVER@</Generation>
          </Resource>
          <Resource>
              <Name>jini-ext</Name>
              <Generation>@JINI-EXT@</Generation>
          </Resource>
          <Resource>
              <Name>jini-core</Name>
              <Generation>@JINI-CORE@</Generation>
          </Resource>
      </Resources>
  </Edition>
  
  
  
  1.1                  avalon-sandbox/console/includes/console.MF
  
  Index: console.MF
  ===================================================================
  Manifest-Version: 1.0
  Service-Class: com.ewarna.lz.services.console.ConsoleImpl
  Specification-Title: Bootstrap Specification
  Specification-Vendor: eWarna.com Sdn Bhd
  Implementation-Vendor: eWarna.com Sdn Bhd
  Specification-Version: @GENERATION@.@EDITION@
  Implementation-Version: @VERSION@
  Implementation-Title: Bootstrap Service Implementation
  
  
  
  
  1.1                  avalon-sandbox/console/includes/console.exc
  
  Index: console.exc
  ===================================================================
  **/.nbattrs
  **/Test*.*
  **/Test*
   
  
  
  
  1.1                  avalon-sandbox/console/includes/console.inc
  
  Index: console.inc
  ===================================================================
  **
  
  
  1.1                  avalon-sandbox/console/lib/log4j-1.2.7.jar
  
  	<<Binary file>>
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/CommandInterpreter.java
  
  Index: CommandInterpreter.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.io.OutputStreamWriter;
  
  import java.net.Socket;
  
  import java.util.TreeMap;
  import java.util.Map;
  import java.util.StringTokenizer;
  
  class CommandInterpreter extends Thread
  {
      static private final String WELCOME_MESSAGE =
      "Welcome to eWarna.com ServiceManager.\n\n" +
      "Type 'help' for a list of available commands.\n\nlogin\n";
  
      private Socket m_Socket;
      private boolean m_Login;
      private BufferedWriter m_Output;
      private BufferedReader m_Input;
      static final private Map m_Commands;
  
      static
      {
          m_Commands = new TreeMap();
          m_Commands.put( "echo", new EchoCmd() );
          m_Commands.put( "exit", new ExitCmd() );
          m_Commands.put( "help", new HelpCmd() );
          m_Commands.put( "login", new LoginCmd() );
          m_Commands.put( "threads", new ThreadCmd() );
          m_Commands.put( "", new DummyCmd() );
      }
  
      static public Map getCommands()
      {
          return m_Commands;
      }
  
      CommandInterpreter( Socket socket )
          throws IOException
      {
          m_Socket = socket;
      }
  
      public void run()
      {
          boolean running = true;
          welcomeMessage();
          while( running )
          {
              try
              {
                  if( ! m_Login )
                      execute( "login" );
                  m_Login = true; //LoginCmd throws an exception if login fails.
                  execute( waitForCommandLine() );
              } catch( InterruptedException e )
              {
                  running = false;
              } catch( Exception e )
              {
                  errorMessage( e.getMessage() );
              }
          }
          try
          {
              m_Socket.close();
          } catch( IOException e )
          {
          }
      }
  
  
      private void execute( String cmdline )
          throws Exception
      {
          String command = parseCommand( cmdline );
          ConsoleCommand cmd = (ConsoleCommand) m_Commands.get( command );
          if( cmd != null )
          {
              String[] args = parseArguments( cmdline );
              cmd.execute( getInput(), getOutput(), args );
          }
          else
              errorMessage( "Unknown command. 'help' for available commands." );
  
      }
  
  
      private String waitForCommandLine()
          throws IOException
      {
          String cmdline = m_Input.readLine().trim();
          return cmdline;
      }
  
      private String parseCommand( String cmdline )
      {
          StringTokenizer st = new StringTokenizer( cmdline, " ", false );
          if( st.hasMoreTokens() )
              return st.nextToken();
          else
              return "";
      }
  
      private String[] parseArguments( String cmdline )
      {
          StringTokenizer st = new StringTokenizer( cmdline, " ", false );
          if( st.hasMoreTokens() )
              st.nextToken();  // remove Command portion;
          String[] args = new String[ st.countTokens() ];
          for( int i=0 ; st.hasMoreTokens() ; i++ )
              args[i] = st.nextToken();
          return args;
      }
  
      private void welcomeMessage()
      {
          try
          {
              getOutput().write( WELCOME_MESSAGE );
              getOutput().newLine();
              getOutput().flush();
          } catch( IOException e )
          {
              e.printStackTrace( System.out );
          }
      }
  
      private void errorMessage( String message )
      {
          try
          {
              getOutput().write( message );
              getOutput().newLine();
              getOutput().flush();
          } catch( IOException e )
          {
              e.printStackTrace( System.out );
          }
      }
  
      private BufferedWriter getOutput()
          throws IOException
      {
          if( m_Output == null )
              openOut();
          return m_Output;
      }
  
      private BufferedReader getInput()
          throws IOException
      {
          if( m_Input == null )
              openIn();
          return m_Input;
      }
  
      private void openOut()
          throws IOException
      {
          m_Output = new BufferedWriter( new OutputStreamWriter( m_Socket.getOutputStream() ) );
      }
  
      private void openIn()
          throws IOException
      {
          m_Input = new BufferedReader( new InputStreamReader( m_Socket.getInputStream() ) );
      }
  
  }
  
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/ConsoleCommand.java
  
  Index: ConsoleCommand.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  
  public interface ConsoleCommand
  {
      void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception;
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/ConsoleImpl.java
  
  Index: ConsoleImpl.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.IOException;
  
  import java.net.InetAddress;
  import java.net.ServerSocket;
  import java.net.Socket;
  
  import java.rmi.RemoteException;
  
  import java.util.ArrayList;
  import java.util.Date;
  import java.util.Iterator;
  import java.util.Map;
  
  import org.apache.log4j.Logger;
  
  public class ConsoleImpl
      implements Runnable
  {
      static final private String CONSOLE_LISTEN_THREAD_NAME = "Console-Listen";
      static private Logger m_Logger;
  
      private int m_Port;
      private ServerSocket m_ServerSocket;
      private Thread m_Thread;
      private ArrayList m_Interpreters;
  
      static
      {
          m_Logger = Logger.getLogger( ConsoleImpl.class );
      }
  
      public ConsoleImpl()
          throws IOException
      {
          m_Interpreters = new ArrayList();
      }
  
  
      public void initialize( Map props )
      {
          if( props != null )
          {
              try
              {
                  m_Port = Integer.parseInt( (String) props.get( "Port" ) );
              } catch( NumberFormatException e )
              {} // ignore
          }
          if( m_Port == 0 )
              m_Port = 3333;
          try
          {
              m_ServerSocket = new ServerSocket( m_Port );
          } catch( IOException e )
          {
              m_Logger.warn( "Could not open the server socket.", e );
          }
      }
  
      public void start()
      {
          /* start new thread for monitoring and updating. */
          m_Logger.info( "Console started." );
          m_Thread = new Thread( this, CONSOLE_LISTEN_THREAD_NAME );
          m_Thread.start();
  //        fireStartedEvent();
      }
  
      public void stop()
      {
          try
          {
              m_Thread.interrupt();
              m_ServerSocket.close();
          } catch( IOException e )
          {}
  //        fireStoppedEvent();
      }
  
      public void dispose()
      {
          m_Logger.info("Console disposed.");
  //        fireDisposedEvent();
      }
  
      public void run()
      {
          boolean running = true;
          while( running )
          {
              try
              {
                  Socket socket = m_ServerSocket.accept();
                  CommandInterpreter intp = new CommandInterpreter( socket );
                  m_Interpreters.add( intp );
                  intp.start();
              } catch( IOException e )
              {
                  running = false;
              } catch( Exception e )
              {
                  m_Logger.warn( "", e );
                  try
                  {
                      Thread.sleep( 60000 );
                  } catch( InterruptedException f )
                  {
                      running = false;
                  }
              }
          }
          Iterator list = m_Interpreters.iterator();
          while( list.hasNext() )
          {
              CommandInterpreter intp = (CommandInterpreter) list.next();
              intp.interrupt();
          }
      }
  
      public String getName()
      {
          return "console";
      }
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/DummyCmd.java
  
  Index: DummyCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  
  public class DummyCmd
      implements ConsoleCommand
  {
      public void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception
      {
          output.newLine();
          output.flush();
      }
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/EchoCmd.java
  
  Index: EchoCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  
  public class EchoCmd
      implements ConsoleCommand
  {
      public void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception
      {
          output.newLine();
          output.write( "echo:  " );
          for( int i=0 ; i < arguments.length ; i++ )
          {
              output.write( arguments[i] );
              output.write( " " );
          }
          output.newLine();
          output.flush();
      }
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/ExitCmd.java
  
  Index: ExitCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  
  public class ExitCmd
      implements ConsoleCommand
  {
      public void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception
      {
          output.write( "Logging out..." );
          output.newLine();
          output.flush();
          throw new InterruptedException( "Exit the session." );
      }
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/HelpCmd.java
  
  Index: HelpCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  
  import java.util.Iterator;
  
  public class HelpCmd
      implements ConsoleCommand
  {
      public void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception
      {
          output.newLine();
          output.write( "Available commands:" );
          output.newLine();
          output.write( "===================" );
          Iterator list = CommandInterpreter.getCommands().keySet().iterator();
          while( list.hasNext() )
          {
              output.write( list.next().toString() );
              output.newLine();
          }
          output.newLine();
          output.flush();
      }
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/LoginCmd.java
  
  Index: LoginCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  import java.io.IOException;
  
  public class LoginCmd
      implements ConsoleCommand
  {
      private final String PASSWORD = "WhatAWonderfulDay";
  
      public void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception
      {
          output.write( "Password:" );
          output.flush();
          String password = input.readLine();
          if( password != null )
          {
              if( ! password.trim().equals( PASSWORD ) )
                  throw new LoginException();
          }
          output.newLine();
          output.write( "Login successful." );
          output.newLine();
          output.newLine();
          output.flush();
      }
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/LoginException.java
  
  Index: LoginException.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  
  public class LoginException extends Exception
  {
      
  }
  
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/TestCaseEchoCmd.java
  
  Index: TestCaseEchoCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedWriter;
  import java.io.BufferedReader;
  import java.io.CharArrayWriter;
  import java.io.CharArrayReader;
  
  import junit.framework.TestCase;
  
  public class TestCaseEchoCmd extends TestCase
  {
      public TestCaseEchoCmd( String name )
      {
          super( name );
      }
  
      public void testEcho()
          throws Exception
      {
          CharArrayReader car = new CharArrayReader( new char[0] );
          BufferedReader in = new BufferedReader( car );
  
          CharArrayWriter caw = new CharArrayWriter();
          BufferedWriter out = new BufferedWriter( caw );
  
          ConsoleCommand cc = new EchoCmd();
  
          String[] arguments = new String[]
          {
              "abc",
              "def", 
              "ghi",
              "I think, therefor I am...... I think"
          };
  
          cc.execute( in, out, arguments );
  
          String result = caw.toString();
  
          assertEquals( m_Expected, result );
      }
  
  
      static private final String m_Expected =
      "\n" +
      "echo:  abc def ghi I think, therefor I am...... I think \n";
  }
  
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/TestCaseHelpCmd.java
  
  Index: TestCaseHelpCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedWriter;
  import java.io.BufferedReader;
  import java.io.CharArrayWriter;
  import java.io.CharArrayReader;
  
  import junit.framework.TestCase;
  
  public class TestCaseHelpCmd extends TestCase
  {
      public TestCaseHelpCmd( String name )
      {
          super( name );
      }
  
      public void testHelp()
          throws Exception
      {
          CharArrayReader car = new CharArrayReader( new char[0] );
          BufferedReader in = new BufferedReader( car );
  
          CharArrayWriter caw = new CharArrayWriter();
          BufferedWriter out = new BufferedWriter( caw );
  
          ConsoleCommand cc = new HelpCmd();
  
          cc.execute( in, out, new String[0] );
  
          String result = caw.toString();
  
          assertEquals( m_Expected, result );
      }
  
  
      static private final String m_Expected =
      "\n" +
      "Available commands:\n" +
      "===================\n" +
      "dispose\n" +
      "echo\n" +
      "exit\n" +
      "help\n" +
      "list\n" +
      "load\n" +
      "login\n" +
      "perf\n" +
      "report\n" +
      "shutdown\n" +
      "start\n" +
      "stop\n" +
      "threads\n" +
      "\n";
  }
  
  
  
  1.1                  avalon-sandbox/console/src/org/apache/avalon/excalibur/console/ThreadCmd.java
  
  Index: ThreadCmd.java
  ===================================================================
  /*
   * Copyright 1997-2004 Apache Software Foundation
   * 
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   * 
   *     http://www.apache.org/licenses/LICENSE-2.0
   * 
   * Unless required by applicable law or agreed to in writing, software
   * distributed under the License is distributed on an "AS IS" BASIS,
   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   * See the License for the specific language governing permissions and
   * limitations under the License.
   */
  package org.apache.avalon.excalibur.console;
  
  import java.io.BufferedReader;
  import java.io.BufferedWriter;
  
  public class ThreadCmd
      implements ConsoleCommand
  {
      public void execute( BufferedReader input, BufferedWriter output, String[] arguments )
          throws Exception
      {
          ThreadGroup tg = Thread.currentThread().getThreadGroup();
          ThreadGroup root = tg;
          while( tg != null )
          {
              root = tg;
              tg = tg.getParent();
          }
          int size = root.activeCount();
          Thread[] threads = new Thread[size+10];
          int created = root.enumerate( threads, true );
          for( int i=0 ; i < created ; i++ )
          {
              output.write( threads[i].toString() );
              output.newLine();
          }
          output.flush();
      }
  }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: cvs-unsubscribe@avalon.apache.org
For additional commands, e-mail: cvs-help@avalon.apache.org