Author: pmouawad
Date: Mon Jan 7 09:44:03 2019
New Revision: 1850622
URL: http://svn.apache.org/viewvc?rev=1850622&view=rev
Log:
Bug 63060 - Report Generator: A generator should only check for folder/files it
generates and only delete those ones
Bugzilla Id: 63060
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/AbstractDataExporter.java
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/TemplateVisitor.java
jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
jmeter/trunk/xdocs/changes.xml
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/AbstractDataExporter.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/AbstractDataExporter.java?rev=1850622&r1=1850621&r2=1850622&view=diff
==============================================================================
---
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/AbstractDataExporter.java
(original)
+++
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/AbstractDataExporter.java
Mon Jan 7 09:44:03 2019
@@ -18,6 +18,8 @@
package org.apache.jmeter.report.dashboard;
import org.apache.commons.lang3.StringUtils;
+import org.apache.jmeter.report.config.ConfigurationException;
+import org.apache.jmeter.report.config.SubConfiguration;
import org.apache.jmeter.report.processor.MapResultData;
import org.apache.jmeter.report.processor.ResultData;
import org.apache.jmeter.report.processor.ValueResultData;
@@ -26,6 +28,7 @@ import org.apache.jmeter.report.processo
* The Class AbstractDataExporter provides a base class for DataExporter.
*/
public abstract class AbstractDataExporter implements DataExporter {
+ private static final String INVALID_PROPERTY_CONFIG_FMT = "Wrong property
\"%s\" in \"%s\" export configuration";
private String name;
@@ -118,4 +121,14 @@ public abstract class AbstractDataExport
this.name = name;
}
+ protected <TProperty> TProperty getPropertyFromConfig(SubConfiguration cfg,
+ String property, TProperty defaultValue, Class<TProperty> clazz)
+ throws ExportException {
+ try {
+ return cfg.getProperty(property, defaultValue, clazz);
+ } catch (ConfigurationException ex) {
+ throw new
ExportException(String.format(INVALID_PROPERTY_CONFIG_FMT,
+ property, getName()), ex);
+ }
+ }
}
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java?rev=1850622&r1=1850621&r2=1850622&view=diff
==============================================================================
---
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java
(original)
+++
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/HtmlTemplateExporter.java
Mon Jan 7 09:44:03 2019
@@ -18,6 +18,7 @@
package org.apache.jmeter.report.dashboard;
import java.io.File;
+import java.io.FileFilter;
import java.io.IOException;
import java.nio.file.Files;
import java.util.HashMap;
@@ -31,7 +32,6 @@ import org.apache.commons.lang3.StringUt
import org.apache.commons.lang3.Validate;
import org.apache.commons.text.StringEscapeUtils;
import org.apache.jmeter.JMeter;
-import org.apache.jmeter.report.config.ConfigurationException;
import org.apache.jmeter.report.config.ExporterConfiguration;
import org.apache.jmeter.report.config.GraphConfiguration;
import org.apache.jmeter.report.config.ReportGeneratorConfiguration;
@@ -60,7 +60,13 @@ import freemarker.template.TemplateExcep
* @since 3.0
*/
public class HtmlTemplateExporter extends AbstractDataExporter {
-
+ private static final FileFilter HTML_REPORT_FILE_FILTER =
+ file ->
+ (file.isFile() &&
+ file.getName().equals("index.html"))
+ || (file.isDirectory() &&
+ (file.getName().equals("content") ||
+ file.getName().startsWith("sbadmin2-")));
private static final String CUSTOM_GRAPH_PREFIX = "custom_";
/** Format used for non null check of parameters. */
@@ -83,16 +89,15 @@ public class HtmlTemplateExporter extend
public static final String TIMESTAMP_FORMAT_MS = "ms";
private static final String INVALID_TEMPLATE_DIRECTORY_FMT = "\"%s\" is
not a valid template directory";
- private static final String INVALID_PROPERTY_CONFIG_FMT = "Wrong property
\"%s\" in \"%s\" export configuration";
// Template directory
private static final String TEMPLATE_DIR = "template_dir";
private static final String TEMPLATE_DIR_NAME_DEFAULT = "report-template";
// Output directory
- private static final String OUTPUT_DIR = "output_dir";
+ static final String OUTPUT_DIR = "output_dir";
// Default output folder name
- private static final String OUTPUT_DIR_NAME_DEFAULT = "report-output";
+ static final String OUTPUT_DIR_NAME_DEFAULT = "report-output";
/**
* Adds to context the value surrounding it with quotes
@@ -326,17 +331,6 @@ public class HtmlTemplateExporter extend
return timestamp;
}
- private <TProperty> TProperty getPropertyFromConfig(SubConfiguration cfg,
- String property, TProperty defaultValue, Class<TProperty> clazz)
- throws ExportException {
- try {
- return cfg.getProperty(property, defaultValue, clazz);
- } catch (ConfigurationException ex) {
- throw new
ExportException(String.format(INVALID_PROPERTY_CONFIG_FMT,
- property, getName()), ex);
- }
- }
-
/*
* (non-Javadoc)
*
@@ -379,7 +373,7 @@ public class HtmlTemplateExporter extend
outputDir = new File(globallyDefinedOutputDir);
}
- JOrphanUtils.canSafelyWriteToFolder(outputDir);
+ JOrphanUtils.canSafelyWriteToFolder(outputDir,
HTML_REPORT_FILE_FILTER);
if (log.isInfoEnabled()) {
log.info("Will generate dashboard in folder: {}",
outputDir.getAbsolutePath());
Modified:
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/TemplateVisitor.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/TemplateVisitor.java?rev=1850622&r1=1850621&r2=1850622&view=diff
==============================================================================
---
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/TemplateVisitor.java
(original)
+++
jmeter/trunk/src/core/org/apache/jmeter/report/dashboard/TemplateVisitor.java
Mon Jan 7 09:44:03 2019
@@ -31,9 +31,10 @@ import java.nio.file.SimpleFileVisitor;
import java.nio.file.StandardCopyOption;
import java.nio.file.attribute.BasicFileAttributes;
-import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
import org.apache.jmeter.report.core.DataContext;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
import freemarker.template.Configuration;
import freemarker.template.Template;
@@ -46,7 +47,7 @@ import freemarker.template.TemplateExcep
* @since 3.0
*/
public class TemplateVisitor extends SimpleFileVisitor<Path> {
-
+ private static final Logger LOGGER =
LoggerFactory.getLogger(TemplateVisitor.class);
public static final String TEMPLATED_FILE_EXT = "fmkr";
private final Path source;
@@ -88,8 +89,7 @@ public class TemplateVisitor extends Sim
try {
Files.copy(file, newDir);
} catch (FileAlreadyExistsException ex) {
- // Set directory empty
- FileUtils.cleanDirectory(newDir.toFile());
+ LOGGER.info("Copying folder from '{}' to '{}', got message:{},
found non empty folder with following content {}, will be ignored", file,
newDir, newDir.toFile().listFiles());
}
return FileVisitResult.CONTINUE;
}
Modified: jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java?rev=1850622&r1=1850621&r2=1850622&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
(original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Mon Jan
7 09:44:03 2019
@@ -20,6 +20,7 @@ package org.apache.jorphan.util;
import java.io.Closeable;
import java.io.File;
+import java.io.FileFilter;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
@@ -588,6 +589,8 @@ public final class JOrphanUtils {
}
/**
+ * Check whether we can write to a folder.
+ * A folder can be written to if if does not contain any file or folder
* Throw {@link IllegalArgumentException} if folder cannot be written to
either:
* <ul>
* <li>Because it exists but is not a folder</li>
@@ -595,18 +598,48 @@ public final class JOrphanUtils {
* <li>Because it does not exist but cannot be created</li>
* </ul>
* @param folder {@link File}
- *
* @throws IllegalArgumentException when folder can't be written to
*/
public static void canSafelyWriteToFolder(File folder) {
- canSafelyWriteToFolder(folder, false);
+ canSafelyWriteToFolder(folder, false, file -> true);
}
+
+
+ /**
+ * Check whether we can write to a folder.
+ * A folder can be written to if folder.listFiles(exporterFileFilter) does
not return any file or folder.
+ * Throw {@link IllegalArgumentException} if folder cannot be written to
either:
+ * <ul>
+ * <li>Because it exists but is not a folder</li>
+ * <li>Because it exists but is not empty using
folder.listFiles(exporterFileFilter)</li>
+ * <li>Because it does not exist but cannot be created</li>
+ * </ul>
+ * @param folder {@link File}
+ * @param exporterFileFilter {@link FileFilter} used to
+ * @throws IllegalArgumentException when folder can't be written to
+ */
+ public static void canSafelyWriteToFolder(File folder, FileFilter
fileFilter) {
+ canSafelyWriteToFolder(folder, false, fileFilter);
+ }
+
+ /**
+ * Check whether we can write to a folder.
+ * @param folder {@link File}
+ * @param deleteFolderContent if true flag whether the folder should be
emptied or a file with the same name deleted
+ * @throws IllegalArgumentException when folder can't be written to
+ * Throw {@link IllegalArgumentException} if folder cannot be written
+ */
+ public static void canSafelyWriteToFolder(File folder, boolean
deleteFolderContent) {
+ canSafelyWriteToFolder(folder, deleteFolderContent, file -> true);
+ }
+
+
/**
* Check whether we can write to a folder.
*
* @param folder which should be checked for writability and emptyness
* @param deleteFolderIfExists flag whether the folder should be emptied
or a file with the same name deleted
- *
+ * @param exporterFileFilter {@link FileFilter}
* @throws IllegalArgumentException when folder can't be written to. That
could have the following reasons:
* <ul>
* <li>it exists but is not a folder</li>
@@ -614,7 +647,7 @@ public final class JOrphanUtils {
* <li>it does not exist but cannot be created</li>
* </ul>
*/
- public static void canSafelyWriteToFolder(File folder, boolean
deleteFolderIfExists) {
+ public static void canSafelyWriteToFolder(File folder, boolean
deleteFolderIfExists, FileFilter exporterFileFilter) {
if(folder.exists()) {
if (folder.isFile()) {
if(deleteFolderIfExists) {
@@ -627,7 +660,7 @@ public final class JOrphanUtils {
+folder.getAbsolutePath()+"' as it is an existing
file");
}
} else {
- File[] listedFiles = folder.listFiles();
+ File[] listedFiles = folder.listFiles(exporterFileFilter);
if(listedFiles != null && listedFiles.length > 0) {
if(deleteFolderIfExists) {
try {
Modified: jmeter/trunk/xdocs/changes.xml
URL:
http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1850622&r1=1850621&r2=1850622&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Mon Jan 7 09:44:03 2019
@@ -116,6 +116,7 @@ of previous time slot as a base. Startin
<h3>Report / Dashboard</h3>
<ul>
<li><bug>62883</bug>Report / Dashboard : Change the way percentiles are
computed for Response Time Percentiles Over Time (successful responses)
graph</li>
+ <li><bug>63060</bug>Report Generator: A generator should only check for
folder/files it generates and only delete those ones</li>
</ul>
<h3>General</h3>