Change order of additonal property loading to be before options

git-svn-id: https://svn.apache.org/repos/asf/jakarta/jmeter/branches/rel-2-1@410911 13f79535-47bb-0310-9956-ffa450edef68

Former-commit-id: 92873bf0a2
This commit is contained in:
Sebastian Bazley 2006-06-01 18:59:54 +00:00
parent 268da3ddb1
commit 8b29bdab6e
3 changed files with 74 additions and 42 deletions

View File

@ -24,7 +24,6 @@ import java.io.FileNotFoundException;
import java.io.IOException;
import java.net.Authenticator;
import java.net.MalformedURLException;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Enumeration;
@ -138,11 +137,8 @@ public class JMeter implements JMeterPlugin {
new CLOptionDescriptor("propfile", CLOptionDescriptor.ARGUMENT_REQUIRED, PROPFILE_OPT,
"the jmeter property file to use"),
new CLOptionDescriptor("addprop", CLOptionDescriptor.ARGUMENT_REQUIRED
| CLOptionDescriptor.DUPLICATES_ALLOWED, // Bug 33920 -
// allow
// multiple
// props
PROPFILE2_OPT, "additional property file(s)"),
| CLOptionDescriptor.DUPLICATES_ALLOWED, PROPFILE2_OPT,
"additional JMeter property file(s)"),
new CLOptionDescriptor("testfile", CLOptionDescriptor.ARGUMENT_REQUIRED, TESTFILE_OPT,
"the jmeter test(.jmx) file to run"),
new CLOptionDescriptor("logfile", CLOptionDescriptor.ARGUMENT_REQUIRED, LOGFILE_OPT,
@ -167,8 +163,9 @@ public class JMeter implements JMeterPlugin {
new CLOptionDescriptor("systemproperty", CLOptionDescriptor.DUPLICATES_ALLOWED
| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, SYSTEM_PROPERTY,
"Define additional system properties"),
new CLOptionDescriptor("systemPropertyFile", CLOptionDescriptor.ARGUMENT_REQUIRED, SYSTEM_PROPFILE,
"Define system properties from a file"),
new CLOptionDescriptor("systemPropertyFile", CLOptionDescriptor.DUPLICATES_ALLOWED
| CLOptionDescriptor.ARGUMENT_REQUIRED, SYSTEM_PROPFILE,
"additional system property file(s)"),
new CLOptionDescriptor("loglevel", CLOptionDescriptor.DUPLICATES_ALLOWED
| CLOptionDescriptor.ARGUMENTS_REQUIRED_2, LOGLEVEL,
"[category=]level e.g. jorphan=INFO or jmeter.util=DEBUG"),
@ -326,13 +323,12 @@ public class JMeter implements JMeterPlugin {
if (!f.canRead() && !f.isDirectory()) {
log.warn("Can't read "+path);
} else {
URL url;
try {
url = new URL("file","",path);// $NON-NLS-1$
NewDriver.addURL(url);
} catch (MalformedURLException e) {
log.warn("Can't create URL for "+path+" "+e);
}
log.info("Adding to classpath: "+path);
try {
NewDriver.addPath(path);
} catch (MalformedURLException e) {
log.warn("Error adding: "+path+" "+e.getLocalizedMessage());
}
}
}
}
@ -408,9 +404,50 @@ public class JMeter implements JMeterPlugin {
JMeterUtils.setJMeterHome(parser.getArgumentById(JMETER_HOME_OPT).getArgument());
}
// Process command line property definitions (can occur multiple times)
Properties jmeterProps = JMeterUtils.getJMeterProperties();
// Add local JMeter properties, if the file is found
String userProp = JMeterUtils.getPropDefault("user.properties",""); //$NON-NLS-1$
if (userProp.length() > 0){ //$NON-NLS-1$
FileInputStream fis=null;
try {
File file = new File(userProp);
if (file.canRead()){
log.info("Loading user properties from: "+userProp);
fis = new FileInputStream(file);
Properties tmp = new Properties();
tmp.load(fis);
jmeterProps.putAll(tmp);
LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
}
} catch (IOException e) {
log.warn("Error loading user property file: " + userProp, e);
} finally {
JOrphanUtils.closeQuietly(fis);
}
}
// Add local system properties, if the file is found
String sysProp = JMeterUtils.getPropDefault("system.properties",""); //$NON-NLS-1$
if (sysProp.length() > 0){ //$NON-NLS-1$
FileInputStream fis=null;
try {
File file = new File(sysProp);
if (file.canRead()){
log.info("Loading system properties from: "+sysProp);
fis = new FileInputStream(file);
System.getProperties().load(fis);
}
} catch (IOException e) {
log.warn("Error loading system property file: " + sysProp, e);
} finally {
JOrphanUtils.closeQuietly(fis);
}
}
// Process command line property definitions
// These can potentially occur multiple times
List clOptions = parser.getArguments();
int size = clOptions.size();
@ -424,7 +461,10 @@ public class JMeter implements JMeterPlugin {
case PROPFILE2_OPT: // Bug 33920 - allow multiple props
try {
fis = new FileInputStream(new File(name));
jmeterProps.load(fis);
Properties tmp = new Properties();
tmp.load(fis);
jmeterProps.putAll(tmp);
LoggingManager.setLoggingLevels(tmp);//Do what would be done earlier
} catch (FileNotFoundException e) {
log.warn("Can't find additional property file: " + name, e);
} catch (IOException e) {
@ -473,25 +513,7 @@ public class JMeter implements JMeterPlugin {
break;
}
}
// Add local properties, if the file is found
if (JMeterUtils.getPropDefault("load.user_properties", true)){ //$NON-NLS-1$
final String name="user.properties"; //$NON-NLS-1$
FileInputStream fis=null;
try {
File file = new File(name);
if (file.canRead()){
log.info("Loading user properties from: "+name);
fis = new FileInputStream(file);
jmeterProps.load(fis);
}
} catch (IOException e) {
log.warn("Error loading user property file: " + name, e);
} finally {
JOrphanUtils.closeQuietly(fis);
}
}
}
public void startServer() {
@ -657,10 +679,10 @@ public class JMeter implements JMeterPlugin {
private static class ListenToTest implements TestListener, Runnable, Remoteable {
int started = 0;
private JMeter _parent;
//NOT YET USED private JMeter _parent;
private ListenToTest(JMeter parent) {
_parent = parent;
//_parent = parent;
}
public synchronized void testEnded(String host) {

View File

@ -108,6 +108,7 @@ sample, and the file name can be included in the sample log file.
<li>Bug 39656 - always use SOAP action if it is provided</li>
<li>Automatically include properties from user.properties file</li>
<li>Add __jexl() function - evaluates Commons JEXL expressions</li>
<li>Optionally load JMeter properties from user.properties and system properties from system.properties.</li>
</ul>
<h4>Bug fixes:</h4>

View File

@ -313,9 +313,10 @@ These are shown below.</p>
your own copy of the jmeter.properties and specify it in the command line.
</p>
<note>
Note: since 2.1.2, you can define additional properties in the file <b>user.properties</b>.
This will be automatically loaded if it is found in the current directory.
To change this behaviour, define the jmeter property <b>load.user_properties=false</b>
Note: since 2.1.2, you can define additional JMeter properties in the file defined by the
JMeter property <b>user.properties</b> which has the default value <b>user.properties</b>.
The file will be automatically loaded if it is found in the current directory.
Similarly, <b>system.properties</b> is used to update system properties.
</note>
<properties>
<property name="ssl.provider">You can specify the class for your SSL
@ -342,6 +343,14 @@ These are shown below.</p>
List of paths that JMeter will search for utility classes.
This is in addition to any jars found in the lib directory.
</property>
<property name="user.properties">
Name of file containing additional JMeter properties.
These are added after the initial property file, but before the -q and -J options are processed.
</property>
<property name="system.properties">
Name of file containing additional system properties.
These are added before the -S and -D options are processed.
</property>
</properties>
<p><b>
See also the comments in the jmeter.properties file for further information on other settings you can change.