Skip to content

Commit

Permalink
Updated dependencies
Browse files Browse the repository at this point in the history
 - removed jxl dependency, xls files will be handled using poi. log4j
1.x was one of the dependency from jxl. By removing this dependency now
log4j also will not get resolved. User can add any library of their
choice for logging.
 - removed commons-lang dependency, will be resolved by commons-io
 - updated commons-io version from 2.5 to 2.11.0
 - removed slf4j-log4j12 dependency. Now log4j is not required or
resolved, removing this dependency.
 - added poi dependency with compile scope. It should exclude transitive
dependencies from poi-ooxml. Updated poi version from 4.1.2 to 5.0.0
  • Loading branch information
cjayswal committed Jan 3, 2022
1 parent a8cfafe commit 61893a5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 36 deletions.
29 changes: 8 additions & 21 deletions ivy.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,15 @@ SOFTWARE.
</dependency>
<dependency org="javax.xml.bind" name="jaxb-api" rev="2.3.1" conf="test->default"/>
<!-- excel -->
<dependency org="net.sourceforge.jexcelapi" name="jxl" rev="2.6.12" conf="compile->default">
<artifact name="jxl" type="jar"></artifact>
</dependency>
<dependency org="org.apache.poi" name="poi" rev="4.1.2" conf="provided->default"/>
<dependency org="org.apache.poi" name="poi-ooxml" rev="4.1.2" conf="provided->default"/>
<dependency org="org.apache.poi" name="poi" rev="5.0.0" conf="compile->default"/>
<dependency org="org.apache.poi" name="poi-ooxml-lite" rev="5.0.0" conf="compile->default"/>
<dependency org="org.apache.poi" name="poi-ooxml" rev="5.0.0" conf="compile->default" transitive="false"/>

<dependency org="commons-codec" name="commons-codec" rev="1.8" conf="compile->default"/>
<dependency org="commons-configuration" name="commons-configuration"
rev="1.7" conf="compile->default"/>
<dependency org="commons-lang" name="commons-lang" rev="2.6" conf="compile->default"/>

<dependency org="commons-io" name="commons-io" rev="2.5" conf="compile->default"/>
<dependency org="commons-io" name="commons-io" rev="2.11.0" conf="compile->default"/>
<dependency org="com.google.code.gson" name="gson" rev="2.8.5" conf="compile->default">
<artifact name="gson" type="jar"></artifact>
</dependency>
Expand All @@ -108,8 +105,7 @@ SOFTWARE.
<dependency org="com.google.inject" name="guice" rev="3.0" conf="compile->default"/>

<dependency org="io.github.lukehutch" name="fast-classpath-scanner" rev="2.0.6" conf="provided->default" />
<dependency org="velocity" name="velocity-dep" rev="1.4"
conf="compile->default" />
<dependency org="velocity" name="velocity-dep" rev="1.4" conf="compile->default" />

<!-- min rev 3.0.0 -->
<dependency org="org.seleniumhq.selenium" name="selenium-remote-driver"
Expand All @@ -123,16 +119,6 @@ SOFTWARE.
<exclude org="org.testng"/>
</dependency>


<!-- ws
<dependency org="xmlunit" name="xmlunit" rev="1.4" />
<dependency org="org.xmlmatchers" name="xml-matchers" rev="0.10" />
<dependency org="com.jayway.jsonpath" name="json-path" rev="0.8.1" />
<dependency org="com.jayway.jsonpath" name="json-path-assert"
rev="0.8.1" />
-->
<dependency org="org.codehaus.groovy" name="groovy-all"
rev="2.1.9" conf="provided->default" />
<dependency org="info.cukes" name="cucumber-java" rev="1.2.4" conf="provided->default"/>
Expand All @@ -143,11 +129,12 @@ SOFTWARE.
<!-- Java EXpression Language (jexl) - implementation of dynamic and scripting features as alternative arrangements for script engine JEP-372 JDK-8236933 -->
<dependency org="org.apache.commons" name="commons-jexl3" rev="3.2.1" conf="compile->default"/>

<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager -->
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.30" conf="compile->default"/>
<!-- https://mvnrepository.com/artifact/io.github.bonigarcia/webdrivermanager
<dependency org="org.slf4j" name="slf4j-log4j12" rev="1.7.30" conf="compile->default"/> -->
<dependency org="io.github.bonigarcia" name="webdrivermanager" rev="4.4.3" conf="compile->default"/>

<!-- https://github.com/SeleniumHQ/selenium/issues/3118 -->
<exclude org="com.codeborne"/>

</dependencies>
</ivy-module>
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
import com.qmetry.qaf.automation.step.client.Scenario;
import com.qmetry.qaf.automation.util.PoiExcelUtil;

import jxl.Workbook;

/**
* @author chirag.jayswal
*/
Expand All @@ -40,12 +38,10 @@ protected void parseFile(String file, List<Scenario> scenarios) {

try {
File scenarioFile = new File(file);

Workbook workbook = Workbook.getWorkbook(scenarioFile);
String[] sheets = workbook.getSheetNames();
for (int sheet = 0; sheet < workbook.getNumberOfSheets(); sheet++) {
String reference = scenarioFile.getPath() + ":" + sheets[sheet];
Object[][] rows = PoiExcelUtil.getExcelData(scenarioFile.getAbsolutePath(), false, sheets[sheet]);
List<String> sheets = PoiExcelUtil.getSheetNames(scenarioFile);
for (String sheet:sheets) {
String reference = scenarioFile.getPath() + ":" + sheet;
Object[][] rows = PoiExcelUtil.getExcelData(scenarioFile.getAbsolutePath(), false, sheet);
processStatements(rows, reference, scenarios);
}
} catch (Exception e) {
Expand Down
26 changes: 19 additions & 7 deletions src/com/qmetry/qaf/automation/util/PoiExcelUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@

import org.apache.commons.logging.Log;
import org.apache.commons.logging.impl.LogFactoryImpl;
import org.apache.poi.hssf.usermodel.HSSFWorkbookFactory;
import org.apache.poi.ss.format.CellDateFormatter;
import org.apache.poi.ss.usermodel.Cell;
import org.apache.poi.ss.usermodel.CellStyle;
Expand All @@ -43,8 +42,9 @@
import org.apache.poi.ss.usermodel.Row.MissingCellPolicy;
import org.apache.poi.ss.usermodel.Sheet;
import org.apache.poi.ss.usermodel.Workbook;
import org.apache.poi.xssf.usermodel.XSSFWorkbookFactory;
import org.apache.poi.ss.usermodel.WorkbookFactory;

import com.qmetry.qaf.automation.core.AutomationError;
import com.qmetry.qaf.automation.testng.DataProviderException;

public class PoiExcelUtil {
Expand Down Expand Up @@ -88,6 +88,21 @@ private static int getFirstCol(Sheet s) {
}
return 0;
}

public static List<String> getSheetNames(File f){
if (!f.exists() || !f.canRead()) {
throw new AutomationError("File not" + (f.exists()? " readable " : " found ") +f.getAbsolutePath());
}
List<String> names = new LinkedList<String>();
try (Workbook workbook = getWorkbook(f)){
if (workbook!=null) {
workbook.iterator().forEachRemaining(s->names.add(s.getSheetName()));
}
} catch (IOException e) {
throw new AutomationError(e);
}
return names;
}

public static Object[][] getExcelData(String file, boolean headerRow, String sheetName) {
Object[][] retobj = null;
Expand Down Expand Up @@ -191,16 +206,13 @@ public static Object[][] getExcelDataAsMap(String file, String sheetName) {

}

private static Workbook getWorkbook(File f) throws IOException {
public static Workbook getWorkbook(File f) throws IOException {
if (!f.exists() || !f.canRead()) {
return null;
}
//open workbook in read-only mode to avoid writing back changes when the document is closed.

if(FileUtil.getExtention(f.getAbsolutePath()).toLowerCase().endsWith("xls")) {
return HSSFWorkbookFactory.create(f, null, true);
}
return XSSFWorkbookFactory.createWorkbook(f, true);
return WorkbookFactory.create(f, null, true);
}

public static Object[][] getTableDataAsMap(String xlFilePath, String tableName, String sheetName) {
Expand Down

1 comment on commit 61893a5

@cjayswal
Copy link
Contributor Author

Choose a reason for hiding this comment

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

With this update no logging library transitive dependency should be resolved. User need to specify logging dependency of their choice , for example log4j, log4j2, slf4j, Logback etc.
Related issue: #398

Please sign in to comment.