poi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kiwiwi...@apache.org
Subject svn commit: r1767473 - in /poi/trunk/src/excelant/java/org/apache/poi/ss/excelant: ExcelAntTask.java util/ExcelAntWorkbookUtil.java
Date Tue, 01 Nov 2016 10:29:02 GMT
Author: kiwiwings
Date: Tue Nov  1 10:29:02 2016
New Revision: 1767473

URL: http://svn.apache.org/viewvc?rev=1767473&view=rev
Log:
findbugs fix

Modified:
    poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java
    poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java

Modified: poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java?rev=1767473&r1=1767472&r2=1767473&view=diff
==============================================================================
--- poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java (original)
+++ poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/ExcelAntTask.java Tue Nov  1 10:29:02
2016
@@ -17,27 +17,19 @@
 
 package org.apache.poi.ss.excelant;
 
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.LinkedList;
+import java.util.Locale;
+
 import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtil;
 import org.apache.poi.ss.excelant.util.ExcelAntWorkbookUtilFactory;
-import org.apache.poi.ss.usermodel.Workbook;
-import org.apache.poi.ss.usermodel.WorkbookFactory;
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 
-import java.io.File;
-import java.io.FileInputStream;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.LinkedList;
-import java.util.Locale;
-
 /**
  * Ant task class for testing Excel workbook cells.
- * 
- * @author Jon Svede ( jon [at] loquatic [dot] com )
- * @author Brian Bush ( brian [dot] bush [at] nrel [dot] gov )
- *
  */
 public class ExcelAntTask extends Task {
     
@@ -98,70 +90,50 @@ public class ExcelAntTask extends Task {
 		log( versionBffr.toString(), Project.MSG_INFO ) ;
 		
 		log( "Using input file: " + excelFileName, Project.MSG_INFO ) ;
-		
-		Workbook targetWorkbook = loadWorkbook() ;
-		if( targetWorkbook == null ) {
-			log( "Unable to load " + excelFileName + 
-					            ".  Verify the file exists and can be read.",
-					            Project.MSG_ERR ) ;
-			return ;
-		}
-		if( tests.size() > 0 ) {
 
-			for (ExcelAntTest test : tests) {
-				log("executing test: " + test.getName(), Project.MSG_DEBUG);
+        workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
+		
+		for (ExcelAntTest test : tests) {
+			log("executing test: " + test.getName(), Project.MSG_DEBUG);
 
-				workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
+			if (workbookUtil == null) {
+			    workbookUtil = ExcelAntWorkbookUtilFactory.getInstance(excelFileName);
+			}
 
-				for (ExcelAntUserDefinedFunction eaUdf : functions) {
-					try {
-						workbookUtil.addFunction(eaUdf.getFunctionAlias(), eaUdf.getClassName());
-					} catch (Exception e) {
-						throw new BuildException(e.getMessage(), e);
-					}
+			for (ExcelAntUserDefinedFunction eaUdf : functions) {
+				try {
+					workbookUtil.addFunction(eaUdf.getFunctionAlias(), eaUdf.getClassName());
+				} catch (Exception e) {
+					throw new BuildException(e.getMessage(), e);
 				}
-				test.setWorkbookUtil(workbookUtil);
+			}
+			test.setWorkbookUtil(workbookUtil);
 
-				if (precision != null && precision.getValue() > 0) {
-					log("setting precision for the test " + test.getName(), Project.MSG_VERBOSE);
-					test.setPrecision(precision.getValue());
-				}
+			if (precision != null && precision.getValue() > 0) {
+				log("setting precision for the test " + test.getName(), Project.MSG_VERBOSE);
+				test.setPrecision(precision.getValue());
+			}
 
-				test.execute();
+			test.execute();
 
-				if (test.didTestPass()) {
-					successCount++;
-				} else {
-					if (failOnError) {
-						throw new BuildException("Test " + test.getName() + " failed.");
-					}
+			if (test.didTestPass()) {
+				successCount++;
+			} else {
+				if (failOnError) {
+					throw new BuildException("Test " + test.getName() + " failed.");
 				}
-				totalCount++;
-
-				workbookUtil = null;
 			}
-			log( successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO ) ;
-			workbookUtil = null ;
+			totalCount++;
+
+			workbookUtil = null;
 		}
-	}
-	
 
-    private Workbook loadWorkbook() {
-        if (excelFileName == null) {
-            throw new BuildException("fileName attribute must be set!",
-                                     getLocation());
-        }
-
-		File workbookFile = new File( excelFileName ) ;
-        try {
-            FileInputStream fis = new FileInputStream( workbookFile ) ;
-            return WorkbookFactory.create( fis ) ;
-        } catch (Exception e) {
-            throw new BuildException("Cannot load file " + excelFileName
-                    + ". Make sure the path and file permissions are correct.", e, getLocation());
-        }
+		if( !tests.isEmpty() ) {
+		    log( successCount + "/" + totalCount + " tests passed.", Project.MSG_INFO );
+		}
+        workbookUtil = null;
 	}
-
+	
 
     /**
      * ExcelAnt depends on external libraries not included in the Ant distribution.

Modified: poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java?rev=1767473&r1=1767472&r2=1767473&view=diff
==============================================================================
--- poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java
(original)
+++ poi/trunk/src/excelant/java/org/apache/poi/ss/excelant/util/ExcelAntWorkbookUtil.java
Tue Nov  1 10:29:02 2016
@@ -91,10 +91,12 @@ public class ExcelAntWorkbookUtil extend
      * @throws BuildException If the workbook cannot be loaded.
      */
     private Workbook loadWorkbook() {
+        if (excelFileName == null) {
+            throw new BuildException("fileName attribute must be set!", getLocation());
+        }
 
-        File workbookFile = new File(excelFileName);
         try {
-            FileInputStream fis = new FileInputStream(workbookFile);
+            FileInputStream fis = new FileInputStream(excelFileName);
             try {
             	workbook = WorkbookFactory.create(fis);
             } finally {



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org


Mime
View raw message