11package com .lazerycode .selenium .extract ;
22
3- import com .lazerycode .selenium .exceptions .* ;
3+ import com .lazerycode .selenium .exceptions .ExpectedFileNotFoundException ;
44import com .lazerycode .selenium .repository .BinaryType ;
55import org .apache .commons .compress .archivers .ArchiveEntry ;
66import org .apache .commons .compress .archivers .ArchiveInputStream ;
1212import org .apache .log4j .Logger ;
1313import org .apache .maven .plugin .MojoFailureException ;
1414
15- import java .io .*;
15+ import java .io .File ;
16+ import java .io .IOException ;
17+ import java .io .InputStream ;
1618import java .util .ArrayList ;
1719import java .util .Enumeration ;
1820
19- import static org .apache .commons .io .IOUtils .copy ;
20-
2121public class FileExtractor {
2222
2323 private static final Logger LOG = Logger .getLogger (FileExtractor .class );
@@ -74,7 +74,7 @@ public String extractFileFromArchive(File downloadedCompressedFile, String extra
7474 */
7575
7676 protected String unzipFile (File downloadedCompressedFile , String extractedToFilePath , BinaryType possibleFilenames ) throws IOException , ExpectedFileNotFoundException {
77- LOG .debug ("Extracting binary from .zip file" );
77+ LOG .debug ("Attempting to extract binary from .zip file... " );
7878 ArrayList <String > filenamesWeAreSearchingFor = possibleFilenames .getBinaryFilenames ();
7979 ZipFile zip = new ZipFile (downloadedCompressedFile );
8080 try {
@@ -92,7 +92,7 @@ protected String unzipFile(File downloadedCompressedFile, String extractedToFile
9292 zip .close ();
9393 }
9494
95- throw new ExpectedFileNotFoundException ("Unable to find any expected filed for " + possibleFilenames .getBinaryTypeAsString ());
95+ throw new ExpectedFileNotFoundException ("Unable to find any expected files for " + possibleFilenames .getBinaryTypeAsString ());
9696 }
9797
9898 /**
@@ -106,15 +106,13 @@ protected String unzipFile(File downloadedCompressedFile, String extractedToFile
106106 */
107107
108108 protected String untarFile (InputStream compressedFileInputStream , String extractedToFilePath , BinaryType possibleFilenames ) throws IOException , ExpectedFileNotFoundException {
109- LOG .debug ("Extracting binary from .tar file" );
109+ LOG .debug ("Attempting to extract binary from a .tar file... " );
110110 ArchiveEntry currentFile ;
111111 ArrayList <String > filenamesWeAreSearchingFor = possibleFilenames .getBinaryFilenames ();
112112 ArchiveInputStream archiveInputStream = new TarArchiveInputStream (compressedFileInputStream );
113113 try {
114114 while ((currentFile = archiveInputStream .getNextEntry ()) != null ) {
115- LOG .debug ("Examining " + currentFile .getName ());
116115 for (String aFilenameWeAreSearchingFor : filenamesWeAreSearchingFor ) {
117- LOG .debug ("Searching for " + aFilenameWeAreSearchingFor + "..." );
118116 if (currentFile .getName ().endsWith (aFilenameWeAreSearchingFor )) {
119117 LOG .debug ("Found: " + currentFile .getName ());
120118 return copyFileToDisk (archiveInputStream , extractedToFilePath , aFilenameWeAreSearchingFor );
@@ -131,10 +129,10 @@ protected String untarFile(InputStream compressedFileInputStream, String extract
131129 /**
132130 * Copy a file from an inputsteam to disk
133131 *
134- * @param inputStream A valid iput stream to read
135- * @param pathToExtractTo Path of the file we want to create
136- * @param filename Filename of the file we want to create
137- * @return Absolute path of the newly created file (Or existing file if overwriteFilesThatExist is set to false)
132+ * @param inputStream A valid iput stream to read
133+ * @param pathToExtractTo Path of the file we want to create
134+ * @param filename Filename of the file we want to create
135+ * @return Absolute path of the newly created file (Or existing file if overwriteFilesThatExist is set to false)
138136 * @throws IOException
139137 */
140138 protected String copyFileToDisk (InputStream inputStream , String pathToExtractTo , String filename ) throws IOException {
@@ -145,6 +143,7 @@ protected String copyFileToDisk(InputStream inputStream, String pathToExtractTo,
145143 String existingFilename = existingFile .getName ();
146144 if (existingFilename .equals (filename )) {
147145 LOG .info ("Binary '" + existingFilename + "' Exists: true" );
146+ LOG .info ("Using existing '" + existingFilename + "'binary." );
148147 return existingFile .getAbsolutePath ();
149148 }
150149 }
@@ -158,9 +157,9 @@ protected String copyFileToDisk(InputStream inputStream, String pathToExtractTo,
158157 }
159158 LOG .info ("Extracting binary '" + filename + "'..." );
160159 FileUtils .copyInputStreamToFile (inputStream , outputFile );
161- LOG .info ("File(s) copied to " + outputFile .getAbsolutePath ());
160+ LOG .info ("Binary copied to " + outputFile .getAbsolutePath ());
162161 if (!outputFile .setExecutable (true ) && !outputFile .canExecute ()) {
163- LOG .warn ("Unable to set executable flag on " + filename );
162+ LOG .warn ("Unable to set executable flag (+x) on " + filename );
164163 }
165164 } finally {
166165 inputStream .close ();
0 commit comments