Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added default jmeter.properties to the plugin #47

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ archivesBaseName = 'jmeter-gradle-plugin'
* Currently supports JMeter versions 2.9, 2.10, 2.11, 2.12, 2.13
*/
ext.jmeterVersion = "2.13"
version = "1.3.3-$jmeterVersion-SNAPSHOT"
version = "1.3.5-$jmeterVersion-SNAPSHOT"

sourceCompatibility=JavaVersion.VERSION_1_6
targetCompatibility=JavaVersion.VERSION_1_6
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class JmeterAbstractTask extends ConventionTask{

private List<String> jmeterPluginJars;

private File workDir;
protected File workDir;

private File jmeterLog;

Expand All @@ -26,12 +26,10 @@ abstract class JmeterAbstractTask extends ConventionTask{
* <p/>
* By default it src/test/jmeter
*/
private File srcDir;
protected File srcDir;

private File jmeterPropertyFile;

private boolean propertyFileChanged;

private String maxHeapSize

private List<File> jmeterUserPropertiesFiles;
Expand Down Expand Up @@ -140,6 +138,10 @@ abstract class JmeterAbstractTask extends ConventionTask{
File upgradeProperties = new File(workDir, "upgrade.properties");
System.setProperty("upgrade_properties", "/" + upgradeProperties.getName());
tempProperties.add(upgradeProperties);

File defaultJmeterProperties = new File(workDir, "jmeter.properties");
System.setProperty("default_jm_properties", "/" + defaultJmeterProperties.getName());
tempProperties.add(defaultJmeterProperties);

for (File f : tempProperties) {
try {
Expand Down Expand Up @@ -206,10 +208,6 @@ abstract class JmeterAbstractTask extends ConventionTask{

void setSrcDir(File srcDir) {
this.srcDir = srcDir
if (!propertyFileChanged) {
System.out.println("Here " + this.getClass().getName());
setJmeterPropertyFile(new File(srcDir, JmeterPluginConvention.JMETER_DEFAULT_PROPERTY_NAME));
}
}

File getJmeterPropertyFile() {
Expand All @@ -218,7 +216,6 @@ abstract class JmeterAbstractTask extends ConventionTask{

void setJmeterPropertyFile(File jmeterPropertyFile) {
this.jmeterPropertyFile = jmeterPropertyFile
propertyFileChanged = true
}

String getMaxHeapSize() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,10 @@ public class JmeterPluginConvention {
*/
private List<File> jmeterUserPropertiesFiles;

public static final String JMETER_DEFAULT_PROPERTY_NAME = "jmeter.properties";

public JmeterPluginConvention(Project project) {
reportDir = new File(project.getBuildDir(), "jmeter-report");
srcDir = new File(project.getProjectDir(), "src/test/jmeter");
jmeterPropertyFile = new File(srcDir.getAbsolutePath() + File.separator + JMETER_DEFAULT_PROPERTY_NAME);
}

public List<File> getJmeterTestFiles() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package com.github.kulya.gradle.plugins.jmeter;

import com.github.kulya.gradle.plugins.jmeter.worker.JMeterRunner;

import org.apache.commons.io.IOUtils;
import org.apache.tools.ant.DirectoryScanner;
import org.gradle.api.GradleException;

import javax.xml.transform.TransformerException;

import java.io.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
Expand Down Expand Up @@ -201,10 +203,26 @@ private String executeJmeterTest(String fileLocation) {
List<String> args = new ArrayList<String>();
args.addAll(Arrays.asList("-n",
"-t", testFile.getCanonicalPath(),
"-l", resultFile.getCanonicalPath(),
"-p", getJmeterPropertyFile().getCanonicalPath()));


"-l", resultFile.getCanonicalPath()
));

File propsInSrcDir = new File(srcDir,"jmeter.properties");
args.add("-p");

//1. Is jmeterPropertyFile defined?
if (getJmeterPropertyFile() != null)
args.add(getJmeterPropertyFile().getCanonicalPath());

//2. Does jmeter.properties exist in $srcDir/test/jmeter
else if (propsInSrcDir.exists())
args.add(propsInSrcDir.getCanonicalPath());

//3. If neither, use the default jmeter.properties
else{
File defPropsFile = new File(workDir + System.getProperty("default_jm_properties"));
args.add(defPropsFile.getCanonicalPath());
}

if(jmeterUserPropertiesFiles!=null)
{
for(File userPropertyFile: jmeterUserPropertiesFiles)
Expand All @@ -220,15 +238,17 @@ private String executeJmeterTest(String fileLocation) {
if (remote) {
args.add("-r");
}
log.debug("JMeter is called with the following command line arguments: " + args.toString());


log.info("JMeter is called with the following command line arguments: " + args.toString());


JmeterSpecs specs = new JmeterSpecs();
specs.getSystemProperties().put("search_paths", System.getProperty("search_paths"));
specs.getSystemProperties().put("jmeter.home", getWorkDir().getAbsolutePath());
specs.getSystemProperties().put("saveservice_properties", System.getProperty("saveservice_properties"));
specs.getSystemProperties().put("upgrade_properties", System.getProperty("upgrade_properties"));
specs.getSystemProperties().put("log_file", System.getProperty("log_file"));
specs.getSystemProperties().put("jmeter.save.saveservice.output_format","xml");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this necessary, as i recall this used to be in the jmeter.properties file.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the line in jmeter.properties (it is commented out)

#jmeter.save.saveservice.output_format=csv

which implies that the default format is xml. But for some reason, when using this plugin to run a jmeter test, the results are in csv format. see #45. I added this line to remedy that.

specs.getJmeterProperties().addAll(args);
specs.setMaxHeapSize(maxHeapSize);
new JMeterRunner().executeJmeterCommand(specs, getWorkDir().getAbsolutePath());
Expand Down
Loading