Show
Ignore:
Timestamp:
02/12/10 13:48:43 (2 years ago)
Author:
amandel
Message:

- use current PMD from public repository
- remove implied dependencies from explicit list
- ignore compiler classpath warning.

Location:
trunk
Files:
2 modified

Legend:

Unmodified
Added
Removed
  • trunk

    • Property svn:ignore
      •  

        old new  
        33eclipse 
        44${env.CRUISECONTROL_HOME} 
         5derbyDB 
         6.byecycle 
  • trunk/src/java/org/jcoderz/phoenix/report/GenericReportReader.java

    r1504 r1606  
    3535import java.io.BufferedReader; 
    3636import java.io.File; 
     37import java.io.FileInputStream; 
     38import java.io.FileNotFoundException; 
    3739import java.io.FileReader; 
    3840import java.io.IOException; 
     
    6769 * Reads reports with format definitions described in the 
    6870 * finding-type-format-definition.xds. 
    69  *  
     71 * 
    7072 * To find the finding type format definition for requested format 
    7173 * the following locations are used: 
    72  *  
     74 * 
    7375 * The name is converted to lower case. 
    74  *  
    75  * A file <i>name</i>.xml is searched in the  
     76 * 
     77 * A file <i>name</i>.xml is searched in the 
    7678 * <code>org.jcoderz.phoenix.report.ftf</code> package. If 
    7779 * this is not found the file is searched in the <code>ftf</code> 
    7880 * directory. The directory must be available through the classpath. 
    79  *  
    80  *  
     81 * 
     82 * 
    8183 * @author Andreas Mandel 
    8284 * 
     
    8890        = GenericReportReader.class.getName(); 
    8991    private static final Logger logger = Logger.getLogger(CLASSNAME); 
    90      
    91     private static final Pattern CODE_LINE_PATTERN  
     92 
     93    private static final Pattern CODE_LINE_PATTERN 
    9294        = Pattern.compile("^.*$", Pattern.MULTILINE); 
    93      
    94     private static final Pattern CARET_LINE_PATTERN  
     95 
     96    private static final Pattern CARET_LINE_PATTERN 
    9597        = Pattern.compile("^\\s*\\^$", Pattern.MULTILINE); 
    96      
     98 
    9799    private static final Map<Origin, GenericReportReader> GENERIC_REPORT_TYPES 
    98100        = new HashMap<Origin, GenericReportReader>(); 
    99101 
    100      
     102 
    101103    private final List<GenericFindingType> mFindingTypes 
    102104        = new ArrayList<GenericFindingType>(); 
    103105 
    104106    private Map<ResourceInfo, List<Item>> mItems; 
    105      
     107 
    106108    private SourceFile mSourceFile; 
    107109 
     
    109111    private final FindingTypeFormat mFindingTypeFormatDescription; 
    110112 
    111     private final int mTextPos;  
     113    private final int mTextPos; 
    112114    private final Origin mOrigin; 
    113115    private final int mFilePos; 
    114116    private final int mLineStart; 
    115117    private final Severity mDefaultSeverity; 
    116      
     118 
    117119    private Matcher mRootMatcher = null; 
    118120 
    119     private GenericReportReader (Origin type)  
     121    private GenericReportReader (Origin type) 
    120122        throws JAXBException 
    121123    { 
     
    123125        mFindingTypeFormatDescription = loadFormatDescription(type); 
    124126        initializeFindingTypes(); 
    125         final FindingDescription root  
     127        final FindingDescription root 
    126128            = mFindingTypeFormatDescription.getRootType(); 
    127         mMessagePattern  
    128             = Pattern.compile(root.getPattern(),  
     129        mMessagePattern 
     130            = Pattern.compile(root.getPattern(), 
    129131                Pattern.MULTILINE); 
    130132        mTextPos =  Integer.parseInt(root.getTextPos()); 
    131133        mFilePos =  Integer.parseInt(root.getFilenamePos()); 
    132         mLineStart = root.isSetLineStartPos()  
     134        mLineStart = root.isSetLineStartPos() 
    133135            ? Integer.parseInt(root.getLineStartPos()) : -1; 
    134         mDefaultSeverity = root.isSetSeverity()  
     136        mDefaultSeverity = root.isSetSeverity() 
    135137            ? root.getSeverity() : Severity.CODE_STYLE; 
    136138    } 
    137139 
    138140    /** 
    139      * Initializes the selected finding type.  
     141     * Initializes the selected finding type. 
    140142     * Might return <code>null</code> if the initialization fails. 
    141143     * CHECKME: Should return a null object? 
     
    157159                { 
    158160                    // TODO: collect this an add it to the findings map later! 
    159                     logger.log(Level.WARNING,  
    160                         "Could not load finding type for '" + findingType  
     161                    logger.log(Level.WARNING, 
     162                        "Could not load finding type for '" + findingType 
    161163                        + "' failed with " + ex.getMessage() + ".", ex); 
    162164                } 
     
    175177        try 
    176178        { 
    177             final String filename  
    178                 = type.toString().toLowerCase(Constants.SYSTEM_LOCALE)  
     179            final String filename 
     180                = type.toString().toLowerCase(Constants.SYSTEM_LOCALE) 
    179181                    + ".xml"; 
    180182            in = GenericReportReader.class.getResourceAsStream( 
     
    185187                    "/ftf/" + filename); 
    186188            } 
     189            if (in == null) 
     190            { 
     191                try 
     192                { 
     193                    in = new FileInputStream(filename); 
     194                } 
     195                catch (FileNotFoundException ex) 
     196                { 
     197                    // in = null; 
     198                } 
     199            } 
    187200            Assert.notNull(in, "report type description " + type); 
    188             final UnmarshalResult unmarshal  
    189                 = JaxbUtil.unmarshal(new InputSource(in),  
     201            final UnmarshalResult unmarshal 
     202                = JaxbUtil.unmarshal(new InputSource(in), 
    190203                    "org.jcoderz.phoenix.report.ftf.jaxb"); 
    191              
     204 
    192205            findingTypeFormatDescription 
    193206                = (FindingTypeFormat) unmarshal.getParsedData(); 
     
    199212        return findingTypeFormatDescription; 
    200213    } 
    201      
     214 
    202215    /** {@inheritDoc} */ 
    203216    public void parse (File f) 
     
    225238        } 
    226239    } 
    227      
     240 
    228241    /** 
    229242     * Reads the given message and tries to find a matching finding type. 
     
    231244     * @return the finding type matching to the message, or null if no such 
    232245     *   type was found. 
    233      * @throws JAXBException if item creation fails.  
     246     * @throws JAXBException if item creation fails. 
    234247     */ 
    235     public Item detectFindingTypeForMessage (String message)  
     248    public Item detectFindingTypeForMessage (String message) 
    236249        throws JAXBException 
    237250    { 
     
    251264       if (logger.isLoggable(Level.FINE)) 
    252265       { 
    253            logger.fine("For text: '"  
     266           logger.fine("For text: '" 
    254267               + StringUtil.trimLength(message, MAX_DEBUG_TEXT_CHARS) 
    255                + "' matched finding: "  
    256                + (result == null ? "null" : result.getFindingType()  
     268               + "' matched finding: " 
     269               + (result == null ? "null" : result.getFindingType() 
    257270               + "'. End at " + mSourceFile.getPos())); 
    258271       } 
     
    262275    private void addPositionByCaret (final Item i) 
    263276    { 
    264         final String text  
    265             = mSourceFile.getContent().substring(mSourceFile.getPos());  
    266         final Matcher codeMat  
     277        final String text 
     278            = mSourceFile.getContent().substring(mSourceFile.getPos()); 
     279        final Matcher codeMat 
    267280            = CODE_LINE_PATTERN.matcher(text); 
    268281        if (codeMat.lookingAt()) 
    269282        { 
    270             final String textAfterCode  
     283            final String textAfterCode 
    271284                = mSourceFile.getContent().substring( 
    272                     mSourceFile.getPos() + codeMat.end() + 1);  
    273             final Matcher caretMat  
     285                    mSourceFile.getPos() + codeMat.end() + 1); 
     286            final Matcher caretMat 
    274287                = CARET_LINE_PATTERN.matcher(textAfterCode); 
    275288            if (caretMat.lookingAt()) 
     
    277290                i.setColumn(caretMat.end()); 
    278291                mSourceFile.setPos( 
    279                     mSourceFile.getPos()  
    280                     + codeMat.end() + 1  
     292                    mSourceFile.getPos() 
     293                    + codeMat.end() + 1 
    281294                    + caretMat.end() + 1); 
    282295            } 
    283296            else 
    284297            { 
    285                 logger.fine("Caret defined but not found for '"  
     298                logger.fine("Caret defined but not found for '" 
    286299                    + i.getFindingType() 
    287                     + "' Code Line: '" + codeMat + "' caretLine: '"  
    288                     + caretMat + "'. text: '"  
     300                    + "' Code Line: '" + codeMat + "' caretLine: '" 
     301                    + caretMat + "'. text: '" 
    289302                    + StringUtil.trimLength( 
    290303                        textAfterCode, MAX_DEBUG_TEXT_CHARS) + "'."); 
     
    293306        else 
    294307        { 
    295             logger.fine("Caret defined but not found for '"  
     308            logger.fine("Caret defined but not found for '" 
    296309                + i.getFindingType() 
    297                 + "' Code Line: '" + codeMat + "'. text: '"  
     310                + "' Code Line: '" + codeMat + "'. text: '" 
    298311                + StringUtil.trimLength( 
    299312                    text, MAX_DEBUG_TEXT_CHARS) + "'."); 
     
    301314    } 
    302315 
    303     private void parseNext ()  
     316    private void parseNext () 
    304317        throws JAXBException 
    305318    { 
     
    317330            if (item == null) 
    318331            { 
    319                 final int pos  
     332                final int pos 
    320333                    = mSourceFile.getContent().indexOf( 
    321334                        '\n', mSourceFile.getPos()); 
    322335                if (pos != -1) 
    323336                { 
    324                     mSourceFile.setPos(pos + 1);   
     337                    mSourceFile.setPos(pos + 1); 
    325338                } 
    326339                else 
    327340                { 
    328                     mSourceFile.setPos(mSourceFile.getContent().length());   
     341                    mSourceFile.setPos(mSourceFile.getContent().length()); 
    329342                } 
    330343            } 
     
    336349                    item.setSeverity(mDefaultSeverity); 
    337350                } 
    338                 if (!item.isSetLine() && mLineStart != -1  
     351                if (!item.isSetLine() && mLineStart != -1 
    339352                    && mRootMatcher.group(mLineStart) != null) 
    340353                { 
     
    366379                    + " '" + StringUtil.trimLength( 
    367380                        mSourceFile.getContent().substring( 
    368                             mSourceFile.getPos()),  
     381                            mSourceFile.getPos()), 
    369382                            MAX_DEBUG_TEXT_CHARS)); 
    370383            } 
     
    407420        else 
    408421        { 
    409             logger.finer("Ignore findings for resource '"  
    410                 + resourceFilename + "' type was "  
     422            logger.finer("Ignore findings for resource '" 
     423                + resourceFilename + "' type was " 
    411424                + item.getFindingType() + "."); 
    412425        } 
    413426    } 
    414      
     427 
    415428    private void initializeFindingTypes () 
    416429    { 
    417         final FindingDescription root  
     430        final FindingDescription root 
    418431            = mFindingTypeFormatDescription.getRootType(); 
    419         final List<FindingDescription> findingTypes  
     432        final List<FindingDescription> findingTypes 
    420433            = mFindingTypeFormatDescription.getFindingType(); 
    421434        for (FindingDescription findingDesc : findingTypes) 
    422435        { 
    423             final GenericFindingType gft  
     436            final GenericFindingType gft 
    424437                = new GenericFindingType(root, findingDesc); 
    425438            mFindingTypes.add(gft); 
     
    428441            mFindingTypes, new GenericFindingType.OrderByPriority()); 
    429442    } 
    430      
    431      
     443 
     444 
    432445    static final class SourceFile 
    433446    { 
     
    435448        private final String mContent; 
    436449        private int mPos; 
    437          
    438         public SourceFile (File file)  
     450 
     451        public SourceFile (File file) 
    439452            throws IOException 
    440453        { 
     
    487500            return mContent; 
    488501        } 
    489          
     502 
    490503        public boolean readFully () 
    491504        {