Coverage Report - org.owasp.dependencycheck.analyzer.ArchiveAnalyzer
 
Classes in this File Line Coverage Branch Coverage Complexity
ArchiveAnalyzer
37%
86/230
20%
28/140
6.588
 
 1  
 /*
 2  
  * This file is part of dependency-check-core.
 3  
  *
 4  
  * Licensed under the Apache License, Version 2.0 (the "License");
 5  
  * you may not use this file except in compliance with the License.
 6  
  * You may obtain a copy of the License at
 7  
  *
 8  
  *     http://www.apache.org/licenses/LICENSE-2.0
 9  
  *
 10  
  * Unless required by applicable law or agreed to in writing, software
 11  
  * distributed under the License is distributed on an "AS IS" BASIS,
 12  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 13  
  * See the License for the specific language governing permissions and
 14  
  * limitations under the License.
 15  
  *
 16  
  * Copyright (c) 2013 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.analyzer;
 19  
 
 20  
 import java.io.BufferedInputStream;
 21  
 import java.io.Closeable;
 22  
 import java.io.File;
 23  
 import java.io.FileFilter;
 24  
 import java.io.FileInputStream;
 25  
 import java.io.FileNotFoundException;
 26  
 import java.io.FileOutputStream;
 27  
 import java.io.IOException;
 28  
 import java.util.ArrayList;
 29  
 import java.util.Collections;
 30  
 import java.util.Enumeration;
 31  
 import java.util.HashSet;
 32  
 import java.util.List;
 33  
 import java.util.Set;
 34  
 
 35  
 import org.apache.commons.compress.archivers.ArchiveEntry;
 36  
 import org.apache.commons.compress.archivers.ArchiveInputStream;
 37  
 import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
 38  
 import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
 39  
 import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
 40  
 import org.apache.commons.compress.archivers.zip.ZipFile;
 41  
 import org.apache.commons.compress.compressors.CompressorInputStream;
 42  
 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
 43  
 import org.apache.commons.compress.compressors.bzip2.BZip2Utils;
 44  
 import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
 45  
 import org.apache.commons.compress.compressors.gzip.GzipUtils;
 46  
 import org.apache.commons.compress.utils.IOUtils;
 47  
 
 48  
 import org.owasp.dependencycheck.Engine;
 49  
 import org.owasp.dependencycheck.analyzer.exception.AnalysisException;
 50  
 import org.owasp.dependencycheck.analyzer.exception.ArchiveExtractionException;
 51  
 import org.owasp.dependencycheck.dependency.Dependency;
 52  
 import org.owasp.dependencycheck.exception.InitializationException;
 53  
 import org.owasp.dependencycheck.utils.FileFilterBuilder;
 54  
 import org.owasp.dependencycheck.utils.FileUtils;
 55  
 import org.owasp.dependencycheck.utils.Settings;
 56  
 
 57  
 import org.slf4j.Logger;
 58  
 import org.slf4j.LoggerFactory;
 59  
 
 60  
 /**
 61  
  * <p>
 62  
  * An analyzer that extracts files from archives and ensures any supported files
 63  
  * contained within the archive are added to the dependency list.</p>
 64  
  *
 65  
  * @author Jeremy Long
 66  
  */
 67  6
 public class ArchiveAnalyzer extends AbstractFileTypeAnalyzer {
 68  
 
 69  
     /**
 70  
      * The logger.
 71  
      */
 72  1
     private static final Logger LOGGER = LoggerFactory.getLogger(ArchiveAnalyzer.class);
 73  
     /**
 74  
      * The count of directories created during analysis. This is used for
 75  
      * creating temporary directories.
 76  
      */
 77  1
     private static int dirCount = 0;
 78  
     /**
 79  
      * The parent directory for the individual directories per archive.
 80  
      */
 81  6
     private File tempFileLocation = null;
 82  
     /**
 83  
      * The max scan depth that the analyzer will recursively extract nested
 84  
      * archives.
 85  
      */
 86  1
     private static final int MAX_SCAN_DEPTH = Settings.getInt("archive.scan.depth", 3);
 87  
     /**
 88  
      * Tracks the current scan/extraction depth for nested archives.
 89  
      */
 90  6
     private int scanDepth = 0;
 91  
 
 92  
     //<editor-fold defaultstate="collapsed" desc="All standard implementation details of Analyzer">
 93  
     /**
 94  
      * The name of the analyzer.
 95  
      */
 96  
     private static final String ANALYZER_NAME = "Archive Analyzer";
 97  
     /**
 98  
      * The phase that this analyzer is intended to run in.
 99  
      */
 100  1
     private static final AnalysisPhase ANALYSIS_PHASE = AnalysisPhase.INITIAL;
 101  
     /**
 102  
      * The set of things we can handle with Zip methods
 103  
      */
 104  1
     private static final Set<String> ZIPPABLES = newHashSet("zip", "ear", "war", "jar", "sar", "apk", "nupkg");
 105  
     /**
 106  
      * The set of file extensions supported by this analyzer. Note for
 107  
      * developers, any additions to this list will need to be explicitly handled
 108  
      * in {@link #extractFiles(File, File, Engine)}.
 109  
      */
 110  1
     private static final Set<String> EXTENSIONS = newHashSet("tar", "gz", "tgz", "bz2", "tbz2");
 111  
 
 112  
     /**
 113  
      * Detects files with extensions to remove from the engine's collection of
 114  
      * dependencies.
 115  
      */
 116  1
     private static final FileFilter REMOVE_FROM_ANALYSIS = FileFilterBuilder.newInstance().addExtensions("zip", "tar", "gz", "tgz", "bz2", "tbz2")
 117  1
             .build();
 118  
 
 119  
     static {
 120  1
         final String additionalZipExt = Settings.getString(Settings.KEYS.ADDITIONAL_ZIP_EXTENSIONS);
 121  1
         if (additionalZipExt != null) {
 122  0
             final String[] ext = additionalZipExt.split("\\s*,\\s*");
 123  0
             Collections.addAll(ZIPPABLES, ext);
 124  
         }
 125  1
         EXTENSIONS.addAll(ZIPPABLES);
 126  
     }
 127  
 
 128  
     /**
 129  
      * The file filter used to filter supported files.
 130  
      */
 131  1
     private static final FileFilter FILTER = FileFilterBuilder.newInstance().addExtensions(EXTENSIONS).build();
 132  
 
 133  
     @Override
 134  
     protected FileFilter getFileFilter() {
 135  859
         return FILTER;
 136  
     }
 137  
 
 138  
     /**
 139  
      * Detects files with .zip extension.
 140  
      */
 141  1
     private static final FileFilter ZIP_FILTER = FileFilterBuilder.newInstance().addExtensions("zip").build();
 142  
 
 143  
     /**
 144  
      * Returns the name of the analyzer.
 145  
      *
 146  
      * @return the name of the analyzer.
 147  
      */
 148  
     @Override
 149  
     public String getName() {
 150  16
         return ANALYZER_NAME;
 151  
     }
 152  
 
 153  
     /**
 154  
      * Returns the phase that the analyzer is intended to run in.
 155  
      *
 156  
      * @return the phase that the analyzer is intended to run in.
 157  
      */
 158  
     @Override
 159  
     public AnalysisPhase getAnalysisPhase() {
 160  4
         return ANALYSIS_PHASE;
 161  
     }
 162  
     //</editor-fold>
 163  
 
 164  
     /**
 165  
      * Returns the key used in the properties file to reference the analyzer's
 166  
      * enabled property.
 167  
      *
 168  
      * @return the analyzer's enabled property setting key
 169  
      */
 170  
     @Override
 171  
     protected String getAnalyzerEnabledSettingKey() {
 172  6
         return Settings.KEYS.ANALYZER_ARCHIVE_ENABLED;
 173  
     }
 174  
 
 175  
     /**
 176  
      * The initialize method does nothing for this Analyzer.
 177  
      *
 178  
      * @throws InitializationException is thrown if there is an exception
 179  
      * deleting or creating temporary files
 180  
      */
 181  
     @Override
 182  
     public void initializeFileTypeAnalyzer() throws InitializationException {
 183  
         try {
 184  1
             final File baseDir = Settings.getTempDirectory();
 185  1
             tempFileLocation = File.createTempFile("check", "tmp", baseDir);
 186  1
             if (!tempFileLocation.delete()) {
 187  0
                 setEnabled(false);
 188  0
                 final String msg = String.format("Unable to delete temporary file '%s'.", tempFileLocation.getAbsolutePath());
 189  0
                 throw new InitializationException(msg);
 190  
             }
 191  1
             if (!tempFileLocation.mkdirs()) {
 192  0
                 setEnabled(false);
 193  0
                 final String msg = String.format("Unable to create directory '%s'.", tempFileLocation.getAbsolutePath());
 194  0
                 throw new InitializationException(msg);
 195  
             }
 196  0
         } catch (IOException ex) {
 197  0
             setEnabled(false);
 198  0
             throw new InitializationException("Unable to create a temporary file", ex);
 199  1
         }
 200  1
     }
 201  
 
 202  
     /**
 203  
      * The close method deletes any temporary files and directories created
 204  
      * during analysis.
 205  
      *
 206  
      * @throws Exception thrown if there is an exception deleting temporary
 207  
      * files
 208  
      */
 209  
     @Override
 210  
     public void close() throws Exception {
 211  2
         if (tempFileLocation != null && tempFileLocation.exists()) {
 212  1
             LOGGER.debug("Attempting to delete temporary files");
 213  1
             final boolean success = FileUtils.delete(tempFileLocation);
 214  1
             if (!success && tempFileLocation.exists()) {
 215  0
                 final String[] l = tempFileLocation.list();
 216  0
                 if (l != null && l.length > 0) {
 217  0
                     LOGGER.warn("Failed to delete some temporary files, see the log for more details");
 218  
                 }
 219  
             }
 220  
         }
 221  2
     }
 222  
 
 223  
     /**
 224  
      * Analyzes a given dependency. If the dependency is an archive, such as a
 225  
      * WAR or EAR, the contents are extracted, scanned, and added to the list of
 226  
      * dependencies within the engine.
 227  
      *
 228  
      * @param dependency the dependency to analyze
 229  
      * @param engine the engine scanning
 230  
      * @throws AnalysisException thrown if there is an analysis exception
 231  
      */
 232  
     @Override
 233  
     public void analyzeFileType(Dependency dependency, Engine engine) throws AnalysisException {
 234  2
         final File f = new File(dependency.getActualFilePath());
 235  2
         final File tmpDir = getNextTempDirectory();
 236  2
         extractFiles(f, tmpDir, engine);
 237  
 
 238  
         //make a copy
 239  2
         final Set<Dependency> dependencySet = findMoreDependencies(engine, tmpDir);
 240  2
         if (!dependencySet.isEmpty()) {
 241  0
             for (Dependency d : dependencySet) {
 242  
                 //fix the dependency's display name and path
 243  0
                 final String displayPath = String.format("%s%s",
 244  0
                         dependency.getFilePath(),
 245  0
                         d.getActualFilePath().substring(tmpDir.getAbsolutePath().length()));
 246  0
                 final String displayName = String.format("%s: %s",
 247  0
                         dependency.getFileName(),
 248  0
                         d.getFileName());
 249  0
                 d.setFilePath(displayPath);
 250  0
                 d.setFileName(displayName);
 251  
 
 252  
                 //TODO - can we get more evidence from the parent? EAR contains module name, etc.
 253  
                 //analyze the dependency (i.e. extract files) if it is a supported type.
 254  0
                 if (this.accept(d.getActualFile()) && scanDepth < MAX_SCAN_DEPTH) {
 255  0
                     scanDepth += 1;
 256  0
                     analyze(d, engine);
 257  0
                     scanDepth -= 1;
 258  
                 }
 259  0
             }
 260  
         }
 261  2
         if (REMOVE_FROM_ANALYSIS.accept(dependency.getActualFile())) {
 262  0
             addDisguisedJarsToDependencies(dependency, engine);
 263  0
             engine.getDependencies().remove(dependency);
 264  
         }
 265  2
         Collections.sort(engine.getDependencies());
 266  2
     }
 267  
 
 268  
     /**
 269  
      * If a zip file was identified as a possible JAR, this method will add the
 270  
      * zip to the list of dependencies.
 271  
      *
 272  
      * @param dependency the zip file
 273  
      * @param engine the engine
 274  
      * @throws AnalysisException thrown if there is an issue
 275  
      */
 276  
     private void addDisguisedJarsToDependencies(Dependency dependency, Engine engine) throws AnalysisException {
 277  0
         if (ZIP_FILTER.accept(dependency.getActualFile()) && isZipFileActuallyJarFile(dependency)) {
 278  0
             final File tdir = getNextTempDirectory();
 279  0
             final String fileName = dependency.getFileName();
 280  
 
 281  0
             LOGGER.info("The zip file '{}' appears to be a JAR file, making a copy and analyzing it as a JAR.", fileName);
 282  
 
 283  0
             final File tmpLoc = new File(tdir, fileName.substring(0, fileName.length() - 3) + "jar");
 284  
             try {
 285  0
                 org.apache.commons.io.FileUtils.copyFile(tdir, tmpLoc);
 286  0
                 final Set<Dependency> dependencySet = findMoreDependencies(engine, tmpLoc);
 287  0
                 if (!dependencySet.isEmpty()) {
 288  0
                     if (dependencySet.size() != 1) {
 289  0
                         LOGGER.info("Deep copy of ZIP to JAR file resulted in more than one dependency?");
 290  
                     }
 291  0
                     for (Dependency d : dependencySet) {
 292  
                         //fix the dependency's display name and path
 293  0
                         d.setFilePath(dependency.getFilePath());
 294  0
                         d.setDisplayFileName(dependency.getFileName());
 295  0
                     }
 296  
                 }
 297  0
             } catch (IOException ex) {
 298  0
                 LOGGER.debug("Unable to perform deep copy on '{}'", dependency.getActualFile().getPath(), ex);
 299  0
             }
 300  
         }
 301  0
     }
 302  
     /**
 303  
      * An empty dependency set.
 304  
      */
 305  1
     private static final Set<Dependency> EMPTY_DEPENDENCY_SET = Collections.emptySet();
 306  
 
 307  
     /**
 308  
      * Scan the given file/folder, and return any new dependencies found.
 309  
      *
 310  
      * @param engine used to scan
 311  
      * @param file target of scanning
 312  
      * @return any dependencies that weren't known to the engine before
 313  
      */
 314  
     private static Set<Dependency> findMoreDependencies(Engine engine, File file) {
 315  2
         final List<Dependency> before = new ArrayList<Dependency>(engine.getDependencies());
 316  2
         engine.scan(file);
 317  2
         final List<Dependency> after = engine.getDependencies();
 318  2
         final boolean sizeChanged = before.size() != after.size();
 319  
         final Set<Dependency> newDependencies;
 320  2
         if (sizeChanged) {
 321  
             //get the new dependencies
 322  0
             newDependencies = new HashSet<Dependency>(after);
 323  0
             newDependencies.removeAll(before);
 324  
         } else {
 325  2
             newDependencies = EMPTY_DEPENDENCY_SET;
 326  
         }
 327  2
         return newDependencies;
 328  
     }
 329  
 
 330  
     /**
 331  
      * Retrieves the next temporary directory to extract an archive too.
 332  
      *
 333  
      * @return a directory
 334  
      * @throws AnalysisException thrown if unable to create temporary directory
 335  
      */
 336  
     private File getNextTempDirectory() throws AnalysisException {
 337  2
         dirCount += 1;
 338  2
         final File directory = new File(tempFileLocation, String.valueOf(dirCount));
 339  
         //getting an exception for some directories not being able to be created; might be because the directory already exists?
 340  2
         if (directory.exists()) {
 341  0
             return getNextTempDirectory();
 342  
         }
 343  2
         if (!directory.mkdirs()) {
 344  0
             final String msg = String.format("Unable to create temp directory '%s'.", directory.getAbsolutePath());
 345  0
             throw new AnalysisException(msg);
 346  
         }
 347  2
         return directory;
 348  
     }
 349  
 
 350  
     /**
 351  
      * Extracts the contents of an archive into the specified directory.
 352  
      *
 353  
      * @param archive an archive file such as a WAR or EAR
 354  
      * @param destination a directory to extract the contents to
 355  
      * @param engine the scanning engine
 356  
      * @throws AnalysisException thrown if the archive is not found
 357  
      */
 358  
     private void extractFiles(File archive, File destination, Engine engine) throws AnalysisException {
 359  2
         if (archive != null && destination != null) {
 360  2
             String archiveExt = FileUtils.getFileExtension(archive.getName());
 361  2
             if (archiveExt == null) {
 362  0
                 return;
 363  
             }
 364  2
             archiveExt = archiveExt.toLowerCase();
 365  
 
 366  
             FileInputStream fis;
 367  
             try {
 368  2
                 fis = new FileInputStream(archive);
 369  0
             } catch (FileNotFoundException ex) {
 370  0
                 LOGGER.debug("", ex);
 371  0
                 throw new AnalysisException("Archive file was not found.", ex);
 372  2
             }
 373  
             try {
 374  2
                 if (ZIPPABLES.contains(archiveExt)) {
 375  2
                     final BufferedInputStream in = new BufferedInputStream(fis);
 376  2
                     ensureReadableJar(archiveExt, in);
 377  2
                     extractArchive(new ZipArchiveInputStream(in), destination, engine);
 378  2
                 } else if ("tar".equals(archiveExt)) {
 379  0
                     extractArchive(new TarArchiveInputStream(new BufferedInputStream(fis)), destination, engine);
 380  0
                 } else if ("gz".equals(archiveExt) || "tgz".equals(archiveExt)) {
 381  0
                     final String uncompressedName = GzipUtils.getUncompressedFilename(archive.getName());
 382  0
                     final File f = new File(destination, uncompressedName);
 383  0
                     if (engine.accept(f)) {
 384  0
                         decompressFile(new GzipCompressorInputStream(new BufferedInputStream(fis)), f);
 385  
                     }
 386  0
                 } else if ("bz2".equals(archiveExt) || "tbz2".equals(archiveExt)) {
 387  0
                     final String uncompressedName = BZip2Utils.getUncompressedFilename(archive.getName());
 388  0
                     final File f = new File(destination, uncompressedName);
 389  0
                     if (engine.accept(f)) {
 390  0
                         decompressFile(new BZip2CompressorInputStream(new BufferedInputStream(fis)), f);
 391  
                     }
 392  
                 }
 393  0
             } catch (ArchiveExtractionException ex) {
 394  0
                 LOGGER.warn("Exception extracting archive '{}'.", archive.getName());
 395  0
                 LOGGER.debug("", ex);
 396  0
             } catch (IOException ex) {
 397  0
                 LOGGER.warn("Exception reading archive '{}'.", archive.getName());
 398  0
                 LOGGER.debug("", ex);
 399  
             } finally {
 400  2
                 close(fis);
 401  2
             }
 402  
         }
 403  2
     }
 404  
 
 405  
     /**
 406  
      * Checks if the file being scanned is a JAR that begins with '#!/bin' which
 407  
      * indicates it is a fully executable jar. If a fully executable JAR is
 408  
      * identified the input stream will be advanced to the start of the actual
 409  
      * JAR file ( skipping the script).
 410  
      *
 411  
      * @see
 412  
      * <a href="http://docs.spring.io/spring-boot/docs/1.3.0.BUILD-SNAPSHOT/reference/htmlsingle/#deployment-install">Installing
 413  
      * Spring Boot Applications</a>
 414  
      * @param archiveExt the file extension
 415  
      * @param in the input stream
 416  
      * @throws IOException thrown if there is an error reading the stream
 417  
      */
 418  
     private void ensureReadableJar(final String archiveExt, BufferedInputStream in) throws IOException {
 419  2
         if ("jar".equals(archiveExt) && in.markSupported()) {
 420  2
             in.mark(7);
 421  2
             final byte[] b = new byte[7];
 422  2
             final int read = in.read(b);
 423  2
             if (read == 7
 424  
                     && b[0] == '#'
 425  
                     && b[1] == '!'
 426  
                     && b[2] == '/'
 427  
                     && b[3] == 'b'
 428  
                     && b[4] == 'i'
 429  
                     && b[5] == 'n'
 430  
                     && b[6] == '/') {
 431  0
                 boolean stillLooking = true;
 432  
                 int chr, nxtChr;
 433  0
                 while (stillLooking && (chr = in.read()) != -1) {
 434  0
                     if (chr == '\n' || chr == '\r') {
 435  0
                         in.mark(4);
 436  0
                         if ((chr = in.read()) != -1) {
 437  0
                             if (chr == 'P' && (chr = in.read()) != -1) {
 438  0
                                 if (chr == 'K' && (chr = in.read()) != -1) {
 439  0
                                     if ((chr == 3 || chr == 5 || chr == 7) && (nxtChr = in.read()) != -1) {
 440  0
                                         if (nxtChr == chr + 1) {
 441  0
                                             stillLooking = false;
 442  0
                                             in.reset();
 443  
                                         }
 444  
                                     }
 445  
                                 }
 446  
                             }
 447  
                         }
 448  
                     }
 449  
                 }
 450  0
             } else {
 451  2
                 in.reset();
 452  
             }
 453  
         }
 454  2
     }
 455  
 
 456  
     /**
 457  
      * Extracts files from an archive.
 458  
      *
 459  
      * @param input the archive to extract files from
 460  
      * @param destination the location to write the files too
 461  
      * @param engine the dependency-check engine
 462  
      * @throws ArchiveExtractionException thrown if there is an exception
 463  
      * extracting files from the archive
 464  
      */
 465  
     private void extractArchive(ArchiveInputStream input, File destination, Engine engine) throws ArchiveExtractionException {
 466  
         ArchiveEntry entry;
 467  
         try {
 468  887
             while ((entry = input.getNextEntry()) != null) {
 469  885
                 final File file = new File(destination, entry.getName());
 470  885
                 if (entry.isDirectory()) {
 471  36
                     if (!file.exists() && !file.mkdirs()) {
 472  0
                         final String msg = String.format("Unable to create directory '%s'.", file.getAbsolutePath());
 473  0
                         throw new AnalysisException(msg);
 474  
                     }
 475  849
                 } else if (engine.accept(file)) {
 476  0
                     extractAcceptedFile(input, file);
 477  
                 }
 478  885
             }
 479  0
         } catch (Throwable ex) {
 480  0
             throw new ArchiveExtractionException(ex);
 481  
         } finally {
 482  2
             close(input);
 483  2
         }
 484  2
     }
 485  
 
 486  
     /**
 487  
      * Extracts a file from an archive.
 488  
      *
 489  
      * @param input the archives input stream
 490  
      * @param file the file to extract
 491  
      * @throws AnalysisException thrown if there is an error
 492  
      */
 493  
     private static void extractAcceptedFile(ArchiveInputStream input, File file) throws AnalysisException {
 494  0
         LOGGER.debug("Extracting '{}'", file.getPath());
 495  0
         FileOutputStream fos = null;
 496  
         try {
 497  0
             final File parent = file.getParentFile();
 498  0
             if (!parent.isDirectory() && !parent.mkdirs()) {
 499  0
                 final String msg = String.format("Unable to build directory '%s'.", parent.getAbsolutePath());
 500  0
                 throw new AnalysisException(msg);
 501  
             }
 502  0
             fos = new FileOutputStream(file);
 503  0
             IOUtils.copy(input, fos);
 504  0
         } catch (FileNotFoundException ex) {
 505  0
             LOGGER.debug("", ex);
 506  0
             final String msg = String.format("Unable to find file '%s'.", file.getName());
 507  0
             throw new AnalysisException(msg, ex);
 508  0
         } catch (IOException ex) {
 509  0
             LOGGER.debug("", ex);
 510  0
             final String msg = String.format("IO Exception while parsing file '%s'.", file.getName());
 511  0
             throw new AnalysisException(msg, ex);
 512  
         } finally {
 513  0
             close(fos);
 514  0
         }
 515  0
     }
 516  
 
 517  
     /**
 518  
      * Decompresses a file.
 519  
      *
 520  
      * @param inputStream the compressed file
 521  
      * @param outputFile the location to write the decompressed file
 522  
      * @throws ArchiveExtractionException thrown if there is an exception
 523  
      * decompressing the file
 524  
      */
 525  
     private void decompressFile(CompressorInputStream inputStream, File outputFile) throws ArchiveExtractionException {
 526  0
         LOGGER.debug("Decompressing '{}'", outputFile.getPath());
 527  0
         FileOutputStream out = null;
 528  
         try {
 529  0
             out = new FileOutputStream(outputFile);
 530  0
             IOUtils.copy(inputStream, out);
 531  0
         } catch (FileNotFoundException ex) {
 532  0
             LOGGER.debug("", ex);
 533  0
             throw new ArchiveExtractionException(ex);
 534  0
         } catch (IOException ex) {
 535  0
             LOGGER.debug("", ex);
 536  0
             throw new ArchiveExtractionException(ex);
 537  
         } finally {
 538  0
             close(out);
 539  0
         }
 540  0
     }
 541  
 
 542  
     /**
 543  
      * Close the given {@link Closeable} instance, ignoring nulls, and logging
 544  
      * any thrown {@link IOException}.
 545  
      *
 546  
      * @param closeable to be closed
 547  
      */
 548  
     private static void close(Closeable closeable) {
 549  4
         if (null != closeable) {
 550  
             try {
 551  4
                 closeable.close();
 552  0
             } catch (IOException ex) {
 553  0
                 LOGGER.trace("", ex);
 554  4
             }
 555  
         }
 556  4
     }
 557  
 
 558  
     /**
 559  
      * Attempts to determine if a zip file is actually a JAR file.
 560  
      *
 561  
      * @param dependency the dependency to check
 562  
      * @return true if the dependency appears to be a JAR file; otherwise false
 563  
      */
 564  
     private boolean isZipFileActuallyJarFile(Dependency dependency) {
 565  0
         boolean isJar = false;
 566  0
         ZipFile zip = null;
 567  
         try {
 568  0
             zip = new ZipFile(dependency.getActualFilePath());
 569  0
             if (zip.getEntry("META-INF/MANIFEST.MF") != null
 570  0
                     || zip.getEntry("META-INF/maven") != null) {
 571  0
                 final Enumeration<ZipArchiveEntry> entries = zip.getEntries();
 572  0
                 while (entries.hasMoreElements()) {
 573  0
                     final ZipArchiveEntry entry = entries.nextElement();
 574  0
                     if (!entry.isDirectory()) {
 575  0
                         final String name = entry.getName().toLowerCase();
 576  0
                         if (name.endsWith(".class")) {
 577  0
                             isJar = true;
 578  0
                             break;
 579  
                         }
 580  
                     }
 581  0
                 }
 582  
             }
 583  0
         } catch (IOException ex) {
 584  0
             LOGGER.debug("Unable to unzip zip file '{}'", dependency.getFilePath(), ex);
 585  
         } finally {
 586  0
             ZipFile.closeQuietly(zip);
 587  0
         }
 588  
 
 589  0
         return isJar;
 590  
     }
 591  
 }