Coverage Report - org.owasp.dependencycheck.exception.ExceptionCollection
 
Classes in this File Line Coverage Branch Coverage Complexity
ExceptionCollection
7%
4/53
0%
0/4
1.133
 
 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) 2016 Jeremy Long. All Rights Reserved.
 17  
  */
 18  
 package org.owasp.dependencycheck.exception;
 19  
 
 20  
 import java.io.PrintStream;
 21  
 import java.io.PrintWriter;
 22  
 import java.util.ArrayList;
 23  
 import java.util.List;
 24  
 
 25  
 /**
 26  
  * A collection of several exceptions.
 27  
  *
 28  
  * @author Jeremy Lomg
 29  
  */
 30  
 public class ExceptionCollection extends Exception {
 31  
 
 32  
     /**
 33  
      * Instantiates a new exception collection.
 34  
      *
 35  
      * @param exceptions a list of exceptions
 36  
      */
 37  
     public ExceptionCollection(List<Throwable> exceptions) {
 38  0
         super();
 39  0
         this.exceptions = exceptions;
 40  0
     }
 41  
 
 42  
     /**
 43  
      * Instantiates a new exception collection.
 44  
      *
 45  
      * @param msg the exception message
 46  
      * @param exceptions a list of exceptions
 47  
      */
 48  
     public ExceptionCollection(String msg, List<Throwable> exceptions) {
 49  1
         super(msg);
 50  1
         this.exceptions = exceptions;
 51  1
     }
 52  
 
 53  
     /**
 54  
      * Instantiates a new exception collection.
 55  
      *
 56  
      * @param exceptions a list of exceptions
 57  
      * @param fatal indicates if the exception that occurred is fatal - meaning
 58  
      * that no analysis was performed.
 59  
      */
 60  
     public ExceptionCollection(List<Throwable> exceptions, boolean fatal) {
 61  0
         super();
 62  0
         this.exceptions = exceptions;
 63  0
         this.fatal = fatal;
 64  0
     }
 65  
 
 66  
     /**
 67  
      * Instantiates a new exception collection.
 68  
      *
 69  
      * @param msg the exception message
 70  
      * @param exceptions a list of exceptions
 71  
      * @param fatal indicates if the exception that occurred is fatal - meaning
 72  
      * that no analysis was performed.
 73  
      */
 74  
     public ExceptionCollection(String msg, List<Throwable> exceptions, boolean fatal) {
 75  0
         super(msg);
 76  0
         this.exceptions = exceptions;
 77  0
         this.fatal = fatal;
 78  0
     }
 79  
 
 80  
     /**
 81  
      * Instantiates a new exception collection.
 82  
      *
 83  
      * @param exceptions a list of exceptions
 84  
      * @param fatal indicates if the exception that occurred is fatal - meaning
 85  
      * that no analysis was performed.
 86  
      */
 87  
     public ExceptionCollection(Throwable exceptions, boolean fatal) {
 88  0
         super();
 89  0
         this.exceptions = new ArrayList<Throwable>();
 90  0
         this.exceptions.add(exceptions);
 91  0
         this.fatal = fatal;
 92  0
     }
 93  
         /**
 94  
      * Instantiates a new exception collection.
 95  
      *
 96  
      * @param msg the exception message
 97  
      * @param exception a list of exceptions
 98  
      */
 99  
     public ExceptionCollection(String msg, Throwable exception) {
 100  0
         super(msg);
 101  0
         this.exceptions = new ArrayList<Throwable>();
 102  0
         this.exceptions.add(exception);
 103  0
         this.fatal = false;
 104  0
     }
 105  
 
 106  
     /**
 107  
      * Instantiates a new exception collection.
 108  
      */
 109  
     public ExceptionCollection() {
 110  0
         super();
 111  0
         this.exceptions = new ArrayList<Throwable>();
 112  0
     }
 113  
     /**
 114  
      * The serial version uid.
 115  
      */
 116  
     private static final long serialVersionUID = 1L;
 117  
 
 118  
     /**
 119  
      * A collection of exceptions.
 120  
      */
 121  
     private List<Throwable> exceptions;
 122  
 
 123  
     /**
 124  
      * Get the value of exceptions.
 125  
      *
 126  
      * @return the value of exceptions
 127  
      */
 128  
     public List<Throwable> getExceptions() {
 129  0
         return exceptions;
 130  
     }
 131  
 
 132  
     /**
 133  
      * Adds an exception to the collection.
 134  
      *
 135  
      * @param ex the exception to add
 136  
      */
 137  
     public void addException(Throwable ex) {
 138  0
         this.exceptions.add(ex);
 139  0
     }
 140  
 
 141  
     /**
 142  
      * Adds an exception to the collection.
 143  
      *
 144  
      * @param ex the exception to add
 145  
      * @param fatal flag indicating if this is a fatal error
 146  
      */
 147  
     public void addException(Throwable ex, boolean fatal) {
 148  0
         addException(ex);
 149  0
         this.fatal = fatal;
 150  0
     }
 151  
 
 152  
     /**
 153  
      * Flag indicating if a fatal exception occurred that would prevent the
 154  
      * attempt at completing the analysis even if exceptions occurred.
 155  
      */
 156  1
     private boolean fatal = false;
 157  
 
 158  
     /**
 159  
      * Get the value of fatal.
 160  
      *
 161  
      * @return the value of fatal
 162  
      */
 163  
     public boolean isFatal() {
 164  0
         return fatal;
 165  
     }
 166  
 
 167  
     /**
 168  
      * Set the value of fatal.
 169  
      *
 170  
      * @param fatal new value of fatal
 171  
      */
 172  
     public void setFatal(boolean fatal) {
 173  0
         this.fatal = fatal;
 174  0
     }
 175  
 
 176  
     /**
 177  
      * Prints the stack trace.
 178  
      *
 179  
      * @param s the writer to print to
 180  
      */
 181  
     @Override
 182  
     public void printStackTrace(PrintWriter s) {
 183  0
         s.println("Multiple Exceptions Occured");
 184  0
         super.printStackTrace(s);
 185  0
         for (Throwable t : this.exceptions) {
 186  0
             s.println("Next Exception:");
 187  0
             t.printStackTrace(s);
 188  0
         }
 189  0
     }
 190  
 
 191  
     /**
 192  
      * Prints the stack trace.
 193  
      *
 194  
      * @param s the stream to write the stack trace to
 195  
      */
 196  
     @Override
 197  
     public void printStackTrace(PrintStream s) {
 198  0
         s.println("Multiple Exceptions Occured");
 199  0
         super.printStackTrace(s);
 200  0
         for (Throwable t : this.exceptions) {
 201  0
             s.println("Next Exception:");
 202  0
             t.printStackTrace(s);
 203  0
         }
 204  0
     }
 205  
 
 206  
     /**
 207  
      * Prints the stack trace to standard error.
 208  
      */
 209  
     @Override
 210  
     public void printStackTrace() {
 211  0
         this.printStackTrace(System.err);
 212  0
     }
 213  
 
 214  
 }