avalon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From blorit...@apache.org
Subject cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test SystemUtilTestCase.java
Date Tue, 12 Feb 2002 06:22:02 GMT
bloritsch    02/02/11 22:22:02

  Modified:    src/scratchpad/org/apache/avalon/excalibur/util
                        CPUParser.java
  Added:       src/scratchpad/org/apache/avalon/excalibur/util/system
                        Linux.java Windows98.java Windows98.java~
               src/scratchpad/org/apache/avalon/excalibur/util/test
                        SystemUtilTestCase.java
  Log:
  update to the System parsing stuff
  
  Revision  Changes    Path
  1.2       +2 -2      jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/CPUParser.java
  
  Index: CPUParser.java
  ===================================================================
  RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/CPUParser.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- CPUParser.java	11 Feb 2002 21:37:24 -0000	1.1
  +++ CPUParser.java	12 Feb 2002 06:22:02 -0000	1.2
  @@ -14,7 +14,7 @@
    * and the generic infomation about them.
    *
    * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
  - * @version CVS $Revision: 1.1 $ $Date: 2002/02/11 21:37:24 $
  + * @version CVS $Revision: 1.2 $ $Date: 2002/02/12 06:22:02 $
    */
   public interface CPUParser
   {
  @@ -27,7 +27,7 @@
        * Return the cpu info for the processors (assuming symetric multiprocessing
        * which means that all CPUs are identical).  The format is:
        *
  -     * ${arch} Family ${family} Model ${model} Stepping ${stepping}, ${manufacturer}
  +     * ${arch} Family ${family} Model ${model} Stepping ${stepping}, ${vendor_id}
        */
       String cpuInfo();
   }
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/system/Linux.java
  
  Index: Linux.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.util.system;
  
  import org.apache.avalon.excalibur.util.CPUParser;
  import org.apache.avalon.excalibur.util.StringUtil;
  
  import java.io.FileReader;
  import java.io.BufferedReader;
  import java.util.Properties;
  
  
  /**
   * Parses the Linux environment--Uses the proc filesystem to determine all the
   * CPU information.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 06:22:02 $
   */
  public final class Linux implements CPUParser
  {
      private final int    m_processors;
      private final String m_cpuInfo;
  
      public Linux()
      {
          int procs = 1;
          String info = "";
  
          try
          {
              BufferedReader reader = new BufferedReader(new FileReader( "/proc/cpuinfo" )
);
              procs = 0;
  
              Properties props = new Properties();
              String line = null;
  
              while ( ( line = reader.readLine() ) != null )
              {
                  String[] args = StringUtil.split( line, ":" );
                  props.setProperty( args[0].trim(), args[1].trim() );
                  if ( args[0].trim().indexOf( "processor" ) >= 0 )
                  {
                      procs++;
                  }
              }
  
              StringBuffer buf = new StringBuffer( System.getProperty("os.arch") );
              buf.append( " Family " );
              buf.append( props.getProperty( "cpu family" ) );
              buf.append( " Model " );
              buf.append( props.getProperty( "model" ) );
              buf.append( " Stepping " );
              buf.append( props.getProperty( "stepping" ) );
              buf.append( ", " );
              buf.append( props.getProperty( "vendor_id" ) );
  
              info = buf.toString();
          }
          catch (Exception e)
          {
              procs = 1;
          }
  
          m_processors = procs;
          m_cpuInfo = info;
      }
  
      /**
       * Return the number of processors available on the machine
       */
      public int numProcessors()
      {
          return m_processors;
      }
  
      /**
       * Return the cpu info for the processors (assuming symetric multiprocessing
       * which means that all CPUs are identical).  The format is:
       *
       * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
       */
      public String cpuInfo()
      {
          return m_cpuInfo;
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/system/Windows98.java
  
  Index: Windows98.java
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.util.system;
  
  import org.apache.avalon.excalibur.util.CPUParser;
  
  import java.io.InputStreamReader;
  import java.io.BufferedReader;
  
  
  /**
   * Parses the Windows 98 environment--the same class should work for other
   * Windows versions, but I only have one to test.  Needs to be updated....
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 06:22:02 $
   */
  public final class Windows98 implements CPUParser
  {
      private final int    m_processors;
      private final String m_cpuInfo;
  
      public Windows98()
      {
          int procs = 1;
          String info = "";
  
          try
          {
              Runtime rt = Runtime.getRuntime();
              Process proc = rt.exec("command.com /C echo %NUMBER_OF_PROCESSORS%");
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                                                          proc.getInputStream() ) );
              String numProcs = reader.readLine();
  
              proc = rt.exec("command.com /C echo %PROCESSOR_IDENTIFIER%");
              reader = new BufferedReader(new InputStreamReader( proc.getInputStream() ) );
              info = reader.readLine();
  
              procs = Integer.parseInt( numProcs );
          }
          catch (Exception e)
          {
          }
  
          m_processors = procs;
          m_cpuInfo = info;
      }
  
      /**
       * Return the number of processors available on the machine
       */
      public int numProcessors()
      {
          return m_processors;
      }
  
      /**
       * Return the cpu info for the processors (assuming symetric multiprocessing
       * which means that all CPUs are identical).  The format is:
       *
       * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
       */
      public String cpuInfo()
      {
          return m_cpuInfo;
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/system/Windows98.java~
  
  Index: Windows98.java~
  ===================================================================
  
  /*
   * Copyright (C) The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.util.system;
  
  import org.apache.avalon.excalibur.util.CPUParser;
  
  import java.io.InputStreamReader;
  import java.io.BufferedReader;
  
  
  /**
   * Parses the Windows 98 environment--the same class should work for other
   * Windows versions, but I only have one to test.
   *
   * @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
   * @version CVS $Revision: 1.1 $ $Date: 2002/02/12 06:22:02 $
   */
  public final class Windows98 implements CPUParser
  {
      private final int    m_processors;
      private final String m_cpuInfo;
  
      public Windows98()
      {
          int procs = 1;
          String info = "";
  
          try
          {
              Runtime rt = Runtime.getRuntime();
              Process proc = rt.exec("command.com /C echo %NUMBER_OF_PROCESSORS%");
              BufferedReader reader = new BufferedReader(new InputStreamReader(
                                                          proc.getInputStream() ) );
              String numProcs = reader.readLine();
  
              proc = rt.exec("command.com /C echo %PROCESSOR_IDENTIFIER%");
              reader = new BufferedReader(new InputStreamReader( proc.getInputStream() ) );
              info = reader.readLine();
  
              procs = Integer.parseInt( numProcs );
          }
          catch (Exception e)
          {
          }
  
          m_processors = procs;
          m_cpuInfo = info;
      }
  
      /**
       * Return the number of processors available on the machine
       */
      public int numProcessors()
      {
          return m_processors;
      }
  
      /**
       * Return the cpu info for the processors (assuming symetric multiprocessing
       * which means that all CPUs are identical).  The format is:
       *
       * ${arch} family ${family} Model ${model} Stepping ${stepping}, ${identifier}
       */
      public String cpuInfo()
      {
          return m_cpuInfo;
      }
  }
  
  
  
  
  1.1                  jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/SystemUtilTestCase.java
  
  Index: SystemUtilTestCase.java
  ===================================================================
  /*
   * Copyright  The Apache Software Foundation. All rights reserved.
   *
   * This software is published under the terms of the Apache Software License
   * version 1.1, a copy of which has been included with this distribution in
   * the LICENSE.txt file.
   */
  package org.apache.avalon.excalibur.util.test;
  
  import junit.framework.TestCase;
  import org.apache.avalon.excalibur.util.SystemUtil;
  
  /**
   * This is used to test SystemUtil for correctness.
   *
   * @author <a href="mailto:peter@apache.org">Peter Donald</a>
   */
  public final class SystemUtilTestCase
      extends TestCase
  {
      public SystemUtilTestCase( String name )
      {
          super( name );
      }
  
      public void testSystemUtil()
      {
          System.out.println("Number of Processors: " + SystemUtil.numProcessors() );
          System.out.println("CPU Info:             " + SystemUtil.cpuInfo() );
          System.out.println("Architecture:         " + SystemUtil.architecture() );
          System.out.println("Operating System:     " + SystemUtil.operatingSystem() );
          System.out.println("OS Version:           " + SystemUtil.osVersion() );
  
          assertEquals( SystemUtil.architecture(), System.getProperty( "os.arch" ) );
          assertEquals( SystemUtil.operatingSystem(), System.getProperty( "os.name" ) );
          assertEquals( SystemUtil.osVersion(), System.getProperty( "os.version" ) );
      }
  }
  
  
  

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


Mime
View raw message