You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by bl...@apache.org on 2002/02/11 22:37:25 UTC
cvs commit: jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test StringUtilTestCase.java
bloritsch 02/02/11 13:37:25
Modified: src/scratchpad/org/apache/avalon/excalibur/util
StringUtil.java
src/scratchpad/org/apache/avalon/excalibur/util/test
StringUtilTestCase.java
Added: src/scratchpad/org/apache/avalon/excalibur/util
CPUParser.java SystemUtil.java
src/scratchpad/org/apache/avalon/excalibur/util/system
Windows2000.java Windows95.java WindowsNT.java
Log:
add SystemUtil functionality along with Windows environment parsing
Revision Changes Path
1.13 +9 -1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/StringUtil.java
Index: StringUtil.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/StringUtil.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- StringUtil.java 31 Dec 2001 21:36:50 -0000 1.12
+++ StringUtil.java 11 Feb 2002 21:37:24 -0000 1.13
@@ -14,7 +14,7 @@
* A set of utility operations that work on or create strings.
*
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
- * @version CVS $Revision: 1.12 $ $Date: 2001/12/31 21:36:50 $
+ * @version CVS $Revision: 1.13 $ $Date: 2002/02/11 21:37:24 $
*/
public final class StringUtil
{
@@ -233,6 +233,14 @@
}
return result;
+ }
+
+ /**
+ * Removes all the whitespace in a string
+ */
+ public final static String stripWhitespace( final String string )
+ {
+ return concat( split( string, " \t\r\n\b" ) );
}
/**
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/CPUParser.java
Index: CPUParser.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;
/**
* This interface is for CPUParser objects that are automagically loaded, and
* perform architecture dependant processing for determining the number of CPUs,
* 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 $
*/
public interface CPUParser
{
/**
* Return the number of processors available on the machine
*/
int numProcessors();
/**
* 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}
*/
String cpuInfo();
}
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/SystemUtil.java
Index: SystemUtil.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;
/**
* A set of utility operations that provide necessary information about the
* architecture of the machine that the system is running on. The values
* provided are automatically determined at JVM startup. The SystemUtils uses
* a plugin architecture so that it can be extended for more than just Linux/
* Windows support.
*
* @author <a href="mailto:bloritsch@apache.org">Berin Loritsch</a>
* @version CVS $Revision: 1.1 $ $Date: 2002/02/11 21:37:24 $
*/
public final class SystemUtil
{
private static final int m_processors;
private static final String m_cpuInfo;
private static final String m_architecture;
private static final String m_osName;
private static final String m_osVersion;
static
{
m_architecture = System.getProperty("os.arch");
m_osName = System.getProperty("os.name");
m_osVersion = System.getProperty("os.version");
int procs = 0;
String info = "";
try {
String name = "org.apache.avalon.excalibur.util.system." +
StringUtil.stripWhitespace( m_osName );
Class klass = Class.forName( name );
CPUParser parser = (CPUParser) klass.newInstance();
procs = parser.numProcessors();
info = parser.cpuInfo();
} catch (Exception e) {
procs = 1; // assume only one processor if we don't have any other
// method of telling
info = m_architecture + " Family n, Model n, Stepping n, Undeterminable";
}
m_processors = procs;
m_cpuInfo = info;
}
/** keep utility from being instantiated */
private SystemUtil() {};
/**
* Return the number of processors available on this machine. This is useful
* in classes like Thread/Processor thread pool models.
*/
public static final int numProcessors()
{
return m_processors;
}
public static final String cpuInfo()
{
return m_cpuInfo;
}
/**
* Return the architecture name
*/
public static final String architecture()
{
return m_architecture;
}
/**
* Return the Operating System name
*/
public static final String operatingSystem()
{
return m_osName;
}
/**
* Return the Operating System version
*/
public static final String osVersion()
{
return m_osVersion;
}
}
1.1 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/system/Windows2000.java
Index: Windows2000.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 2000 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/11 21:37:24 $
*/
public final class Windows2000 implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
public Windows2000()
{
int procs = 1;
String info = "";
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd.exe /C echo %NUMBER_OF_PROCESSORS%");
BufferedReader reader = new BufferedReader(new InputStreamReader(
proc.getInputStream() ) );
String numProcs = reader.readLine();
proc = rt.exec("cmd.exe /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/Windows95.java
Index: Windows95.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 95 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/11 21:37:24 $
*/
public final class Windows95 implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
public Windows2000()
{
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/WindowsNT.java
Index: WindowsNT.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 2000 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/11 21:37:24 $
*/
public final class Windows2000 implements CPUParser
{
private final int m_processors;
private final String m_cpuInfo;
public Windows2000()
{
int procs = 1;
String info = "";
try
{
Runtime rt = Runtime.getRuntime();
Process proc = rt.exec("cmd.exe /C echo %NUMBER_OF_PROCESSORS%");
BufferedReader reader = new BufferedReader(new InputStreamReader(
proc.getInputStream() ) );
String numProcs = reader.readLine();
proc = rt.exec("cmd.exe /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.6 +5 -0 jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/StringUtilTestCase.java
Index: StringUtilTestCase.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-excalibur/src/scratchpad/org/apache/avalon/excalibur/util/test/StringUtilTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- StringUtilTestCase.java 11 Dec 2001 09:53:37 -0000 1.5
+++ StringUtilTestCase.java 11 Feb 2002 21:37:24 -0000 1.6
@@ -160,6 +160,11 @@
}));
}
+ public void testStripWhiteSpace()
+ {
+ assertEquals( "TestMeTruly", StringUtil.stripWhitespace(" Test Me Truly") );
+ }
+
private void assertEqualArrays( final String[] s1, final String[] s2 )
{
assertEquals( "Array Length Equality", s1.length, s2.length );
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>