001: /*
002: * FindBugs - Find Bugs in Java programs
003: * Copyright (C) 2005, University of Maryland
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2.1 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: */
019:
020: package edu.umd.cs.findbugs.ba;
021:
022: import edu.umd.cs.findbugs.AbstractBugReporter;
023: import edu.umd.cs.findbugs.annotations.SuppressWarnings;
024: import edu.umd.cs.findbugs.classfile.ClassDescriptor;
025: import edu.umd.cs.findbugs.classfile.MethodDescriptor;
026:
027: /**
028: * DebugRepositoryLookupFailureCallback implementation for debugging.
029: * (Test drivers, etc.) It just prints a message and exits.
030: *
031: * @author David Hovemeyer
032: */
033: public class DebugRepositoryLookupFailureCallback implements
034: RepositoryLookupFailureCallback {
035:
036: /* (non-Javadoc)
037: * @see edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback#reportMissingClass(java.lang.ClassNotFoundException)
038: */
039: @SuppressWarnings("DM_EXIT")
040: public void reportMissingClass(ClassNotFoundException ex) {
041: String missing = AbstractBugReporter.getMissingClassName(ex);
042: if (missing.charAt(0) == '[')
043: return;
044:
045: System.out.println("Missing class");
046: ex.printStackTrace();
047: System.exit(1);
048: }
049:
050: /* (non-Javadoc)
051: * @see edu.umd.cs.findbugs.classfile.IErrorLogger#reportMissingClass(edu.umd.cs.findbugs.classfile.ClassDescriptor)
052: */
053: @SuppressWarnings("DM_EXIT")
054: public void reportMissingClass(ClassDescriptor classDescriptor) {
055: System.out.println("Missing class: " + classDescriptor);
056: System.exit(1);
057: }
058:
059: /* (non-Javadoc)
060: * @see edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback#logError(java.lang.String)
061: */
062: @SuppressWarnings("DM_EXIT")
063: public void logError(String message) {
064: System.err.println("Error: " + message);
065: System.exit(1);
066: }
067:
068: /* (non-Javadoc)
069: * @see edu.umd.cs.findbugs.ba.RepositoryLookupFailureCallback#logError(java.lang.String, java.lang.Throwable)
070: */
071: @SuppressWarnings("DM_EXIT")
072: public void logError(String message, Throwable e) {
073: if (e instanceof MissingClassException) {
074: MissingClassException missingClassEx = (MissingClassException) e;
075: ClassNotFoundException cnfe = missingClassEx
076: .getClassNotFoundException();
077:
078: reportMissingClass(cnfe);
079: // Don't report dataflow analysis exceptions due to missing classes.
080: // Too much noise.
081: return;
082:
083: }
084: if (e instanceof MethodUnprofitableException) {
085: // TODO: log this
086: return;
087: }
088: System.err.println("Error: " + message);
089: e.printStackTrace();
090: System.exit(1);
091: }
092:
093: /**
094: * Report that we skipped some analysis of a method
095: * @param method
096: */
097: public void reportSkippedAnalysis(MethodDescriptor method) {
098: System.err.println("Skipping " + method);
099: }
100: }
|