jmeter-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pmoua...@apache.org
Subject svn commit: r1828168 - in /jmeter/trunk: src/core/org/apache/jmeter/JMeter.java src/jorphan/org/apache/jorphan/util/JOrphanUtils.java xdocs/changes.xml xdocs/usermanual/get-started.xml
Date Mon, 02 Apr 2018 13:38:08 GMT
Author: pmouawad
Date: Mon Apr  2 13:38:08 2018
New Revision: 1828168

URL: http://svn.apache.org/viewvc?rev=1828168&view=rev
Log:
Bug 62243 - Dashboard : make option "--forceDeleteResultFile"/"-f" option delete folder referenced
by "-o" option
Bugzilla Id: 62243

Modified:
    jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
    jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java
    jmeter/trunk/xdocs/changes.xml
    jmeter/trunk/xdocs/usermanual/get-started.xml

Modified: jmeter/trunk/src/core/org/apache/jmeter/JMeter.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/JMeter.java?rev=1828168&r1=1828167&r2=1828168&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/JMeter.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/JMeter.java Mon Apr  2 13:38:08 2018
@@ -278,7 +278,7 @@ public class JMeter implements JMeterPlu
      private static final CLOptionDescriptor D_FORCE_DELETE_RESULT_FILE =
             new CLOptionDescriptor("forceDeleteResultFile",
                     CLOptionDescriptor.ARGUMENT_DISALLOWED, FORCE_DELETE_RESULT_FILE,
-                    "force delete existing results files before start the test");
+                    "force delete existing results files and web report folder if present
before starting the test");
 
     private static final String[][] DEFAULT_ICONS = {
             { "org.apache.jmeter.control.gui.TestPlanGui",               "org/apache/jmeter/images/beaker.gif"
},     //$NON-NLS-1$ $NON-NLS-2$
@@ -517,14 +517,14 @@ public class JMeter implements JMeterPlu
                 CLOption testReportOpt = parser.getArgumentById(REPORT_GENERATING_OPT);
                 if (testReportOpt != null) { // generate report from existing file
                     String reportFile = testReportOpt.getArgument();
-                    extractAndSetReportOutputFolder(parser);
+                    extractAndSetReportOutputFolder(parser, false);
                     ReportGenerator generator = new ReportGenerator(reportFile, null);
                     generator.generate();
                 } else if (parser.getArgumentById(NONGUI_OPT) == null) { // not non-GUI =>
GUI
                     startGui(testFile);
                     startOptionalServers();
                 } else { // NON-GUI must be true
-                    extractAndSetReportOutputFolder(parser);
+                    extractAndSetReportOutputFolder(parser, deleteResultFile);
                     
                     CLOption rem = parser.getArgumentById(REMOTE_OPT_PARAM);
                     if (rem == null) {
@@ -562,14 +562,14 @@ public class JMeter implements JMeterPlu
      * @param parser {@link CLArgsParser}
      * @throws IllegalArgumentException
      */
-    private void extractAndSetReportOutputFolder(CLArgsParser parser) {
+    private void extractAndSetReportOutputFolder(CLArgsParser parser, boolean deleteResultFile)
{
         CLOption reportOutputFolderOpt = parser
                 .getArgumentById(REPORT_OUTPUT_FOLDER_OPT);
         if(reportOutputFolderOpt != null) {
             String reportOutputFolder = parser.getArgumentById(REPORT_OUTPUT_FOLDER_OPT).getArgument();
             File reportOutputFolderAsFile = new File(reportOutputFolder);
 
-            JOrphanUtils.canSafelyWriteToFolder(reportOutputFolderAsFile);
+            JOrphanUtils.canSafelyWriteToFolder(reportOutputFolderAsFile, deleteResultFile);
             final String reportOutputFolderAbsPath = reportOutputFolderAsFile.getAbsolutePath();
             log.info("Setting property '{}' to:'{}'", JMETER_REPORT_OUTPUT_DIR_PROPERTY,
reportOutputFolderAbsPath);
             JMeterUtils.setProperty(JMETER_REPORT_OUTPUT_DIR_PROPERTY, reportOutputFolderAbsPath);

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=1828168&r1=1828167&r2=1828168&view=diff
==============================================================================
--- jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java (original)
+++ jmeter/trunk/src/jorphan/org/apache/jorphan/util/JOrphanUtils.java Mon Apr  2 13:38:08
2018
@@ -31,6 +31,7 @@ import java.util.Map;
 import java.util.StringTokenizer;
 import java.util.regex.Matcher;
 
+import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang3.StringUtils;
 
 /**
@@ -43,7 +44,6 @@ import org.apache.commons.lang3.StringUt
 public final class JOrphanUtils {
 
     private static final int DEFAULT_CHUNK_SIZE = 4096;
-
     /**
      * Private constructor to prevent instantiation.
      */
@@ -593,20 +593,52 @@ public final class JOrphanUtils {
      *  <li>Because it exists but is not empty</li>
      *  <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);
+    }
+    /**
+     * 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</li>
+     *  <li>Because it does not exist but cannot be created</li>
+     * </ul>
      * @param folder {@link File}
+     * @param deleteFolderIfExists 
+     * 
      * @throws IllegalArgumentException when folder can't be written to
      */
-    public static void canSafelyWriteToFolder(File folder)
-            throws IllegalArgumentException {
+    public static void canSafelyWriteToFolder(File folder, boolean deleteFolderIfExists)
{
         if(folder.exists()) {
             if (folder.isFile()) {
-                throw new IllegalArgumentException("Cannot write to '"
+                if(deleteFolderIfExists) {
+                    if(!folder.delete()) {
+                        throw new IllegalArgumentException("Cannot write to '"
+                                +folder.getAbsolutePath()+"' as it is an existing file and
delete failed");
+                    }
+                } else {
+                    throw new IllegalArgumentException("Cannot write to '"
                         +folder.getAbsolutePath()+"' as it is an existing file");
+                }
             } else {
                 File[] listedFiles = folder.listFiles();
                 if(listedFiles != null && listedFiles.length > 0) {
-                    throw new IllegalArgumentException("Cannot write to '"
+                    if(deleteFolderIfExists) {
+                        try {
+                            FileUtils.deleteDirectory(folder);
+                            folder.mkdir();
+                        } catch(IOException ex) {
+                            throw new IllegalArgumentException("Cannot write to '"
+                                    +folder.getAbsolutePath()+"' as folder is not empty and
cleanup failed with error:"+ex.getMessage(), ex);
+                        }
+                    } else {
+                        throw new IllegalArgumentException("Cannot write to '"
                             +folder.getAbsolutePath()+"' as folder is not empty");
+                    }
                 }
             }
         } else {

Modified: jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1828168&r1=1828167&r2=1828168&view=diff
==============================================================================
--- jmeter/trunk/xdocs/changes.xml [utf-8] (original)
+++ jmeter/trunk/xdocs/changes.xml [utf-8] Mon Apr  2 13:38:08 2018
@@ -121,6 +121,7 @@ this behaviour, set <code>httpclient.res
 
 <h3>Report / Dashboard</h3>
 <ul>
+    <li><bug>62243</bug>Dashboard : make option "<code>--forceDeleteResultFile</code>"/"<code>-f</code>"
option delete folder referenced by "<code>-o</code>" option</li>
 </ul>
 
 <h3>General</h3>

Modified: jmeter/trunk/xdocs/usermanual/get-started.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/get-started.xml?rev=1828168&r1=1828167&r2=1828168&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/get-started.xml (original)
+++ jmeter/trunk/xdocs/usermanual/get-started.xml Mon Apr  2 13:38:08 2018
@@ -764,7 +764,7 @@ These are shown below.</p>
     -S, --systemPropertyFile &lt;argument&gt;
         additional system property file(s)
     -f, --forceDeleteResultFile
-        force delete existing results files before start the test
+        force delete existing results files and web report folder if present before starting
the test
     -L, --loglevel &lt;argument&gt;=&lt;value&gt;
         [category=]level e.g. jorphan=INFO, jmeter.util=DEBUG or com.example.foo=WARN
     -r, --runremote



Mime
View raw message