public class JMeterUtils extends java.lang.Object implements UnitTestManager
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
RES_KEY_PFX |
Constructor and Description |
---|
JMeterUtils() |
Modifier and Type | Method and Description |
---|---|
static void |
addLocaleChangeListener(LocaleChangeListener listener) |
static void |
applyHiDPI(javax.swing.JTable table)
Apply HiDPI mode management to
JTable |
static void |
applyHiDPIOnFonts()
Apply HiDPI scale factor on font if HiDPI mode is enabled
|
static void |
applyScaleOnFonts(float scale)
Apply HiDPI scale factor on fonts
|
static void |
clearMatcherMemory(org.apache.oro.text.regex.Perl5Matcher matcher,
org.apache.oro.text.regex.Pattern pattern)
Hack to make matcher clean the two internal buffers it keeps in memory which size is equivalent to
the unzipped page size
|
static java.util.List<java.lang.String> |
findClassesThatExtend(java.lang.Class<?> superClass)
Convenience method for
ClassFinder.findClassesThatExtend(String[], Class[], boolean)
with the option to include inner classes in the search set to false
and the path list is derived from JMeterUtils.getSearchPaths(). |
static java.io.File |
findFile(java.lang.String fileName)
Find a file in the current directory or in the JMeter bin directory.
|
static java.lang.String |
formatJMeterExportedVariableName(java.lang.String elementName) |
static java.lang.String |
getDelimiter(java.lang.String delimiterValue)
Return delimiterValue handling the TAB case
|
static boolean |
getHiDPIMode()
Provide info, whether we run in HiDPI mode
|
static double |
getHiDPIScaleFactor()
Provide info about the HiDPI scale factor
|
static javax.swing.ImageIcon |
getImage(java.lang.String name)
This looks for the requested image in the classpath under
org.apache.jmeter.images.
|
static javax.swing.ImageIcon |
getImage(java.lang.String name,
java.lang.String description)
This looks for the requested image in the classpath under
org.apache.jmeter.images.
|
static java.lang.String |
getJMeterBinDir()
Get the JMeter bin directory - does not include the trailing separator.
|
static java.lang.String |
getJMeterCopyright()
Gets the JMeter copyright.
|
static java.lang.String |
getJMeterHome()
Get the JMeter home directory - does not include the trailing separator.
|
static java.util.Properties |
getJMeterProperties()
This gets the currently defined appProperties.
|
static java.lang.String |
getJMeterVersion()
Gets the JMeter Version.
|
static java.util.Locale |
getLocale()
Gets the current locale.
|
static java.lang.String |
getLocaleString(java.lang.String locale)
Get the locale name as a resource.
|
static java.lang.String |
getLocalHostFullName()
Returns the cached result from calling
InetAddress.getLocalHost().getCanonicalHostName()
|
static java.lang.String |
getLocalHostIP()
Returns the cached result from calling
InetAddress.getLocalHost().getHostAddress()
|
static java.lang.String |
getLocalHostName()
Returns the cached result from calling
InetAddress.getLocalHost().getHostName()
|
static org.apache.oro.text.regex.Perl5Matcher |
getMatcher()
Gets Perl5Matcher for this thread.
|
static java.lang.String |
getParsedLabel(java.lang.String key)
To get I18N label from properties file
|
static org.apache.oro.text.regex.Pattern |
getPattern(java.lang.String expression)
Get a compiled expression from the pattern cache (READ_ONLY).
|
static org.apache.oro.text.regex.Pattern |
getPattern(java.lang.String expression,
int options)
Get a compiled expression from the pattern cache.
|
static org.apache.oro.text.PatternCacheLRU |
getPatternCache() |
static boolean |
getPropDefault(java.lang.String propName,
boolean defaultVal)
Get a boolean value with default if not present.
|
static float |
getPropDefault(java.lang.String propName,
float defaultVal)
Get a float value with default if not present.
|
static int |
getPropDefault(java.lang.String propName,
int defaultVal)
Get a int value with default if not present.
|
static long |
getPropDefault(java.lang.String propName,
long defaultVal)
Get a long value with default if not present.
|
static java.lang.String |
getPropDefault(java.lang.String propName,
java.lang.String defaultVal)
Get a String value with default if not present.
|
static java.util.Properties |
getProperties(java.lang.String file)
This method is used by the init method to load the property file that may
even reside in the user space, or in the classpath under
org.apache.jmeter.jmeter.properties.
|
static java.lang.String |
getProperty(java.lang.String propName)
Get the value of a JMeter property.
|
static int |
getRandomInt(int r)
Provide random numbers
|
static java.lang.String |
getResourceFileAsText(java.lang.String name) |
static java.lang.String |
getResString(java.lang.String key)
Gets the resource string for this key.
|
static java.lang.String |
getResString(java.lang.String key,
java.util.Locale forcedLocale)
Gets the resource string for this key in Locale.
|
static java.lang.String |
getResString(java.lang.String key,
java.lang.String defaultValue)
Deprecated.
Only intended for use in development; use
getResString(String) normally
|
static java.lang.String[] |
getSearchPaths()
Generate a list of paths to search.
|
static void |
helpGC()
Help GC by triggering GC and finalization
|
void |
initializeProperties(java.lang.String file)
Your implementation will be handed the filename that was provided to
AllTests as a configuration file.
|
static void |
initLocale()
Initialise the JMeter Locale
|
static void |
initLogging()
Deprecated.
does not do anything anymore
|
static boolean |
isExpertMode()
Determine whether we are in 'expert' mode.
|
static boolean |
isTestRunning() |
static void |
loadJMeterProperties(java.lang.String file)
Load the JMeter properties file; if not found, then
default to "org/apache/jmeter/jmeter.properties" from the classpath
c.f. loadProperties
|
static java.util.Properties |
loadProperties(java.lang.String file)
This method loads a property file that may reside in the user space, or
in the classpath
|
static java.util.Properties |
loadProperties(java.lang.String file,
java.util.Properties defaultProps)
This method loads a property file that may reside in the user space, or
in the classpath
|
static java.util.LinkedHashMap<java.lang.String,java.lang.String> |
parseHeaders(java.lang.String headers)
Split line into name/value pairs and remove colon ':'
|
static void |
refreshUI()
Refresh UI after LAF change or resizing
|
static void |
removeLocaleChangeListener(LocaleChangeListener listener) |
static void |
reportErrorToUser(java.lang.String errorMsg)
Report an error through a dialog box.
|
static void |
reportErrorToUser(java.lang.String errorMsg,
java.lang.Exception exception)
Report an error through a dialog box.
|
static void |
reportErrorToUser(java.lang.String errorMsg,
java.lang.String titleMsg)
Report an error through a dialog box in GUI mode
or in logs and stdout in Non GUI mode
|
static void |
reportErrorToUser(java.lang.String errorMsg,
java.lang.String titleMsg,
java.lang.Exception exception)
Report an error through a dialog box in GUI mode
or in logs and stdout in Non GUI mode
|
static void |
runSafe(boolean synchronous,
java.lang.Runnable runnable)
Run the runnable in AWT Thread if current thread is not AWT thread
otherwise runs call
SwingUtilities.invokeAndWait(Runnable) |
static void |
runSafe(java.lang.Runnable runnable)
Run the runnable in AWT Thread if current thread is not AWT thread
otherwise runs call
SwingUtilities.invokeAndWait(Runnable) |
static void |
setJMeterHome(java.lang.String home) |
static void |
setLocale(java.util.Locale loc)
Changes the current locale: re-reads resource strings and notifies
listeners.
|
static java.lang.Object |
setProperty(java.lang.String propName,
java.lang.String propValue)
Set a String value
|
static void |
setupXStreamSecurityPolicy(com.thoughtworks.xstream.XStream xstream)
Setup default security policy
|
static java.lang.String |
unsplit(java.lang.Object[] splittee,
java.lang.Object splitChar)
Takes an array of strings and a tokenizer character, and returns a string
of all the strings concatenated with the tokenizer string in between each
one.
|
static java.lang.String |
unsplit(java.lang.Object[] splittee,
java.lang.Object splitChar,
java.lang.String def)
Takes an array of strings and a tokenizer character, and returns a string
of all the strings concatenated with the tokenizer string in between each
one.
|
public static final java.lang.String RES_KEY_PFX
public static org.apache.oro.text.regex.Perl5Matcher getMatcher()
Perl5Matcher
for this threadpublic static java.util.Properties getProperties(java.lang.String file)
file
- the file to loadgetJMeterProperties()
,
loadJMeterProperties(String)
,
initLocale()
@Deprecated public static void initLogging()
public static void initLocale()
public static void loadJMeterProperties(java.lang.String file)
c.f. loadProperties
file
- Name of the file from which the JMeter properties should be loadedpublic static java.util.Properties loadProperties(java.lang.String file)
file
- the file to loadpublic static java.util.Properties loadProperties(java.lang.String file, java.util.Properties defaultProps)
file
- the file to loaddefaultProps
- a set of default propertiespublic static org.apache.oro.text.PatternCacheLRU getPatternCache()
public static org.apache.oro.text.regex.Pattern getPattern(java.lang.String expression) throws org.apache.oro.text.MalformedCachePatternException
expression
- regular expression to be looked uporg.apache.oro.text.MalformedCachePatternException
- (Runtime)
This should be caught for expressions that may vary (e.g. user input)public static org.apache.oro.text.regex.Pattern getPattern(java.lang.String expression, int options) throws org.apache.oro.text.MalformedCachePatternException
expression
- REoptions
- e.g. READ_ONLY_MASK
org.apache.oro.text.MalformedCachePatternException
- (Runtime)
This should be caught for expressions that may vary (e.g. user input)public void initializeProperties(java.lang.String file)
UnitTestManager
initializeProperties
in interface UnitTestManager
file
- path to the configuration filepublic static java.util.List<java.lang.String> findClassesThatExtend(java.lang.Class<?> superClass) throws java.io.IOException
ClassFinder.findClassesThatExtend(String[], Class[], boolean)
with the option to include inner classes in the search set to false
and the path list is derived from JMeterUtils.getSearchPaths().superClass
- - single class to search forjava.io.IOException
- when the used ClassFinder
throws one while searching for the classpublic static java.lang.String[] getSearchPaths()
public static int getRandomInt(int r)
r
- -
the upper bound (exclusive)int
public static void setLocale(java.util.Locale loc)
loc
- -
new localepublic static java.util.Locale getLocale()
public static void addLocaleChangeListener(LocaleChangeListener listener)
public static void removeLocaleChangeListener(LocaleChangeListener listener)
public static java.lang.String getResString(java.lang.String key)
key
- the key in the resource filepublic static java.lang.String getResString(java.lang.String key, java.util.Locale forcedLocale)
key
- the key in the resource fileforcedLocale
- Force a particular locale@Deprecated public static java.lang.String getResString(java.lang.String key, java.lang.String defaultValue)
key
- the key in the resource filedefaultValue
- -
the default valuepublic static java.lang.String getParsedLabel(java.lang.String key)
key
- in messages.propertiespublic static java.lang.String getLocaleString(java.lang.String locale)
locale
- namepublic static java.util.Properties getJMeterProperties()
getProperties(String)
or loadJMeterProperties(String)
method has been called.loadJMeterProperties(String)
has not been calledgetProperties(String)
,
loadJMeterProperties(String)
public static javax.swing.ImageIcon getImage(java.lang.String name)
name
- Description of Parameterpublic static javax.swing.ImageIcon getImage(java.lang.String name, java.lang.String description)
name
- the name of the imagedescription
- the description of the imagepublic static java.lang.String getResourceFileAsText(java.lang.String name)
public static int getPropDefault(java.lang.String propName, int defaultVal)
propName
- the name of the property.defaultVal
- the default value.public static boolean getPropDefault(java.lang.String propName, boolean defaultVal)
propName
- the name of the property.defaultVal
- the default value.public static long getPropDefault(java.lang.String propName, long defaultVal)
propName
- the name of the property.defaultVal
- the default value.public static float getPropDefault(java.lang.String propName, float defaultVal)
propName
- the name of the property.defaultVal
- the default value.public static java.lang.String getPropDefault(java.lang.String propName, java.lang.String defaultVal)
propName
- the name of the property.defaultVal
- the default value.public static java.lang.String getProperty(java.lang.String propName)
propName
- the name of the property.public static java.lang.Object setProperty(java.lang.String propName, java.lang.String propValue)
propName
- the name of the property.propValue
- the value of the propertypublic static void reportErrorToUser(java.lang.String errorMsg)
errorMsg
- - the error message.public static void reportErrorToUser(java.lang.String errorMsg, java.lang.String titleMsg)
errorMsg
- - the error message.titleMsg
- - title stringpublic static void reportErrorToUser(java.lang.String errorMsg, java.lang.Exception exception)
errorMsg
- - the error message.exception
- Exception
public static void reportErrorToUser(java.lang.String errorMsg, java.lang.String titleMsg, java.lang.Exception exception)
errorMsg
- - the error message.titleMsg
- - title stringexception
- Exceptionpublic static java.lang.String unsplit(java.lang.Object[] splittee, java.lang.Object splitChar)
splittee
- Array of Objects to be concatenated.splitChar
- Object to unsplit the strings with.public static java.lang.String unsplit(java.lang.Object[] splittee, java.lang.Object splitChar, java.lang.String def)
splittee
- Array of Objects to be concatenated.splitChar
- Object to unsplit the strings with.def
- Default value to replace null values in array.public static boolean isTestRunning()
public static java.lang.String getJMeterHome()
public static java.lang.String getJMeterBinDir()
public static void setJMeterHome(java.lang.String home)
public static java.lang.String getJMeterVersion()
public static java.lang.String getJMeterCopyright()
public static boolean isExpertMode()
public static java.io.File findFile(java.lang.String fileName)
fileName
- the name of the file to findpublic static java.lang.String getLocalHostIP()
public static java.lang.String getLocalHostName()
public static java.lang.String getLocalHostFullName()
public static java.util.LinkedHashMap<java.lang.String,java.lang.String> parseHeaders(java.lang.String headers)
headers
- multi-line string headerspublic static void runSafe(java.lang.Runnable runnable)
SwingUtilities.invokeAndWait(Runnable)
runnable
- Runnable
public static void runSafe(boolean synchronous, java.lang.Runnable runnable)
SwingUtilities.invokeAndWait(Runnable)
synchronous
- flag, whether we will wait for the AWT Thread to finish its job.runnable
- Runnable
public static void helpGC()
public static void clearMatcherMemory(org.apache.oro.text.regex.Perl5Matcher matcher, org.apache.oro.text.regex.Pattern pattern)
matcher
- Perl5Matcher
pattern
- Patternpublic static boolean getHiDPIMode()
true
if we run in HiDPI mode, false
otherwisepublic static double getHiDPIScaleFactor()
public static void applyHiDPI(javax.swing.JTable table)
JTable
table
- the JTable
which should be adapted for HiDPI modepublic static java.lang.String getDelimiter(java.lang.String delimiterValue)
delimiterValue
- Delimited valueJMeterError
- if delimiterValue has a length different from 1public static void applyHiDPIOnFonts()
public static void applyScaleOnFonts(float scale)
scale
- float scale to applypublic static final void refreshUI()
public static void setupXStreamSecurityPolicy(com.thoughtworks.xstream.XStream xstream)
xstream
- XStream
public static java.lang.String formatJMeterExportedVariableName(java.lang.String elementName)
elementName
- String elementNameCopyright © 1998-2018 Apache Software Foundation. All Rights Reserved.