You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@jmeter.apache.org by pm...@apache.org on 2017/01/18 21:35:21 UTC

svn commit: r1779390 - in /jmeter/trunk: src/components/org/apache/jmeter/config/ src/core/org/apache/jmeter/services/ xdocs/usermanual/

Author: pmouawad
Date: Wed Jan 18 21:35:20 2017
New Revision: 1779390

URL: http://svn.apache.org/viewvc?rev=1779390&view=rev
Log:
Bug 60603 - CSV Data Set Config : Add a property to ignore first line 
Bugzilla Id: 60603

Modified:
    jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
    jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetBeanInfo.java
    jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources.properties
    jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources_fr.properties
    jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
    jmeter/trunk/xdocs/usermanual/component_reference.xml

Modified: jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java?rev=1779390&r1=1779389&r2=1779390&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSet.java Wed Jan 18 21:35:20 2017
@@ -24,6 +24,7 @@ import java.beans.Introspector;
 import java.io.IOException;
 import java.util.ResourceBundle;
 
+import org.apache.commons.lang3.StringUtils;
 import org.apache.jmeter.engine.event.LoopIterationEvent;
 import org.apache.jmeter.engine.event.LoopIterationListener;
 import org.apache.jmeter.engine.util.NoConfigMerge;
@@ -97,6 +98,8 @@ public class CSVDataSet extends ConfigTe
     
     private boolean firstLineIsNames = false;
 
+    private boolean ignoreFirstLine = false;
+
     private Object readResolve(){
         recycle = true;
         return this;
@@ -174,7 +177,7 @@ public class CSVDataSet extends ConfigTe
                     break;
             }
             final String names = getVariableNames();
-            if (names == null || names.length()==0) {
+            if (StringUtils.isEmpty(names)) {
                 String header = server.reserveFile(fileName, getFileEncoding(), alias, true);
                 try {
                     vars = CSVSaveService.csvSplitString(header, delim.charAt(0));
@@ -183,7 +186,7 @@ public class CSVDataSet extends ConfigTe
                     throw new IllegalArgumentException("Could not split CSV header line from file:" + fileName,e);
                 }
             } else {
-                server.reserveFile(fileName, getFileEncoding(), alias);
+                server.reserveFile(fileName, getFileEncoding(), alias, ignoreFirstLine);
                 vars = JOrphanUtils.split(names, ","); // $NON-NLS-1$
             }
             trimVarNames(vars);
@@ -194,9 +197,11 @@ public class CSVDataSet extends ConfigTe
         String[] lineValues = {};
         try {
             if (getQuotedData()) {
-                lineValues = server.getParsedLine(alias, recycle, firstLineIsNames, delim.charAt(0));
+                lineValues = server.getParsedLine(alias, recycle, 
+                        firstLineIsNames || ignoreFirstLine, delim.charAt(0));
             } else {
-                String line = server.readLine(alias, recycle, firstLineIsNames);
+                String line = server.readLine(alias, recycle, 
+                        firstLineIsNames || ignoreFirstLine);
                 lineValues = JOrphanUtils.split(line, delim, false);
             }
             for (int a = 0; a < vars.length && a < lineValues.length; a++) {
@@ -310,4 +315,18 @@ public class CSVDataSet extends ConfigTe
     public void setShareMode(String value) {
         this.shareMode = value;
     }
+
+    /**
+     * @return the ignoreFirstLine
+     */
+    public boolean isIgnoreFirstLine() {
+        return ignoreFirstLine;
+    }
+
+    /**
+     * @param ignoreFirstLine the ignoreFirstLine to set
+     */
+    public void setIgnoreFirstLine(boolean ignoreFirstLine) {
+        this.ignoreFirstLine = ignoreFirstLine;
+    }
 }

Modified: jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetBeanInfo.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetBeanInfo.java?rev=1779390&r1=1779389&r2=1779390&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetBeanInfo.java (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetBeanInfo.java Wed Jan 18 21:35:20 2017
@@ -29,6 +29,7 @@ public class CSVDataSetBeanInfo extends
     private static final String FILENAME = "filename";               //$NON-NLS-1$
     private static final String FILE_ENCODING = "fileEncoding";      //$NON-NLS-1$
     private static final String VARIABLE_NAMES = "variableNames";    //$NON-NLS-1$
+    private static final String IGNORE_FIRST_LINE = "ignoreFirstLine";    //$NON-NLS-1$
     private static final String DELIMITER = "delimiter";             //$NON-NLS-1$
     private static final String RECYCLE = "recycle";                 //$NON-NLS-1$
     private static final String STOPTHREAD = "stopThread";           //$NON-NLS-1$
@@ -52,7 +53,9 @@ public class CSVDataSetBeanInfo extends
         super(CSVDataSet.class);
 
         createPropertyGroup("csv_data",             //$NON-NLS-1$
-                new String[] { FILENAME, FILE_ENCODING, VARIABLE_NAMES, DELIMITER, QUOTED_DATA, RECYCLE, STOPTHREAD, SHAREMODE });
+                new String[] { FILENAME, FILE_ENCODING, VARIABLE_NAMES, 
+                        IGNORE_FIRST_LINE, DELIMITER, QUOTED_DATA, 
+                        RECYCLE, STOPTHREAD, SHAREMODE });
 
         PropertyDescriptor p = property(FILENAME);
         p.setValue(NOT_UNDEFINED, Boolean.TRUE);
@@ -69,6 +72,10 @@ public class CSVDataSetBeanInfo extends
         p.setValue(DEFAULT, "");        //$NON-NLS-1$
         p.setValue(NOT_EXPRESSION, Boolean.TRUE);
 
+        p = property(IGNORE_FIRST_LINE);
+        p.setValue(NOT_UNDEFINED, Boolean.TRUE);
+        p.setValue(DEFAULT, Boolean.FALSE);
+
         p = property(DELIMITER);
         p.setValue(NOT_UNDEFINED, Boolean.TRUE);
         p.setValue(DEFAULT, ",");        //$NON-NLS-1$

Modified: jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources.properties?rev=1779390&r1=1779389&r2=1779390&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources.properties (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources.properties Wed Jan 18 21:35:20 2017
@@ -19,6 +19,8 @@ filename.displayName=Filename
 filename.shortDescription=Name of the file that holds the cvs data (relative or absolute filename)
 fileEncoding.displayName=File encoding
 fileEncoding.shortDescription=The character set encoding used in the file
+ignoreFirstLine.displayName=Ignore first line (only used if Variable Names is not empty)
+ignoreFirstLine.shortDescription=Ignore first line of CSV file, it will only be used used if Variable Names is not empty, if Variable Names is empty the first line must contain the headers.
 variableNames.displayName=Variable Names (comma-delimited)
 variableNames.shortDescription=List your variable names in order to match the order of columns in your csv data. Keep it empty to use the first line of the file for variable names.
 delimiter.displayName=Delimiter (use '\\t' for tab)

Modified: jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources_fr.properties
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources_fr.properties?rev=1779390&r1=1779389&r2=1779390&view=diff
==============================================================================
--- jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources_fr.properties (original)
+++ jmeter/trunk/src/components/org/apache/jmeter/config/CSVDataSetResources_fr.properties Wed Jan 18 21:35:20 2017
@@ -22,6 +22,8 @@ fileEncoding.displayName=Encodage du fic
 fileEncoding.shortDescription=Encodage des caract\u00E8res utilis\u00E9s dans le fichier
 filename.displayName=Nom de fichier 
 filename.shortDescription=Nom du fichier qui contient des donn\u00E9es CSV (chemin relatif ou absolu)
+ignoreFirstLine.displayName=Ignorer la premi\u00E8re ligne (utilis\u00E9 uniquement si Noms des Variables n'est pas vide)
+ignoreFirstLine.shortDescription=Ignorer la premi\u00E8re ligne du fichier CSV, utilis\u00E9 uniquement si Noms des Variables n'est pas vide, si si Noms des Variables est vide la premi\u00E8re doit contenir les ent\u00E8tes.
 quotedData.displayName=Autoriser les donn\u00E9es avec des quotes ? 
 quotedData.shortDescription=Permettre aux valeurs des donn\u00E9es CSV d'\u00EAtre quot\u00E9es ?
 recycle.displayName=Recycler en fin de fichier (EOF) ? 

Modified: jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java
URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java?rev=1779390&r1=1779389&r2=1779390&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/services/FileServer.java Wed Jan 18 21:35:20 2017
@@ -330,16 +330,16 @@ public class FileServer {
         return readLine(filename, recycle, false);
     }
    /**
-     * Get the next line of the named file.
+     * Get the next line of the named file
      *
      * @param filename the filename or alias that was used to reserve the file
      * @param recycle - should file be restarted at EOF?
-     * @param firstLineIsNames - 1st line is fields names
+     * @param ignoreFirstLine - Ignore first line
      * @return String containing the next line in the file (null if EOF reached and not recycle)
      * @throws IOException when reading of the file fails, or the file was not reserved properly
      */
     public synchronized String readLine(String filename, boolean recycle, 
-            boolean firstLineIsNames) throws IOException {
+            boolean ignoreFirstLine) throws IOException {
         FileEntry fileEntry = files.get(filename);
         if (fileEntry != null) {
             if (fileEntry.inputOutputObject == null) {
@@ -353,7 +353,7 @@ public class FileServer {
                 reader.close();
                 reader = createBufferedReader(fileEntry);
                 fileEntry.inputOutputObject = reader;
-                if (firstLineIsNames) {
+                if (ignoreFirstLine) {
                     // read first line and forget
                     reader.readLine();//NOSONAR
                 }
@@ -369,24 +369,33 @@ public class FileServer {
      * 
      * @param alias the file name or alias
      * @param recycle whether the file should be re-started on EOF
-     * @param firstLineIsNames whether the file contains a file header
+     * @param ignoreFirstLine whether the file contains a file header which will be ignored
      * @param delim the delimiter to use for parsing
      * @return the parsed line, will be empty if the file is at EOF
      * @throws IOException when reading of the aliased file fails, or the file was not reserved properly
      */
-    public synchronized String[] getParsedLine(String alias, boolean recycle, boolean firstLineIsNames, char delim) throws IOException {
-        BufferedReader reader = getReader(alias, recycle, firstLineIsNames);
+    public synchronized String[] getParsedLine(String alias, boolean recycle, boolean ignoreFirstLine, char delim) throws IOException {
+        BufferedReader reader = getReader(alias, recycle, ignoreFirstLine);
         return CSVSaveService.csvReadFile(reader, delim);
     }
 
-    private BufferedReader getReader(String alias, boolean recycle, boolean firstLineIsNames) throws IOException {
+    /**
+     * Return BufferedReader handling close if EOF reached and recycle is true 
+     * and ignoring first line if ignoreFirstLine is true
+     * @param alias String alias
+     * @param recycle Recycle at eof
+     * @param ignoreFirstLine Ignore first line
+     * @return {@link BufferedReader}
+     * @throws IOException
+     */
+    private BufferedReader getReader(String alias, boolean recycle, boolean ignoreFirstLine) throws IOException {
         FileEntry fileEntry = files.get(alias);
         if (fileEntry != null) {
             BufferedReader reader;
             if (fileEntry.inputOutputObject == null) {
                 reader = createBufferedReader(fileEntry);
                 fileEntry.inputOutputObject = reader;
-                if (firstLineIsNames) {
+                if (ignoreFirstLine) {
                     // read first line and forget
                     reader.readLine(); //NOSONAR
                 }                
@@ -401,7 +410,7 @@ public class FileServer {
                         reader.close();
                         reader = createBufferedReader(fileEntry);
                         fileEntry.inputOutputObject = reader;
-                        if (firstLineIsNames) {
+                        if (ignoreFirstLine) {
                             // read first line and forget
                             reader.readLine(); //NOSONAR
                         }                

Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml
URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1779390&r1=1779389&r2=1779390&view=diff
==============================================================================
--- jmeter/trunk/xdocs/usermanual/component_reference.xml (original)
+++ jmeter/trunk/xdocs/usermanual/component_reference.xml Wed Jan 18 21:35:20 2017
@@ -3606,6 +3606,10 @@ By default, a Graphite implementation is
   if the variable name field empty, then the first line of the file is read and interpreted as the list of column names.
   The names must be separated by the delimiter character. They can be quoted using double-quotes.
   </property>
+  <property name="Ignore first line (only used if Variable Names is not empty)" required="No">
+  Ignore first line of CSV file, it will only be used used if Variable Names is not empty, 
+  if Variable Names is empty the first line must contain the headers.
+  </property>
   <property name="Delimiter" required="Yes">Delimiter to be used to split the records in the file.
   If there are fewer values on the line than there are variables the remaining variables are not updated -
   so they will retain their previous value (if any).</property>