Project Report: fawkez

Packagesummary org.jcoderz.phoenix.report

org.jcoderz.phoenix.report.SourceDirectoryReader

LineHitsNoteSource
1  /*
2   * $Id: SourceDirectoryReader.java 1509 2009-06-07 20:14:07Z amandel $
3   *
4   * Copyright 2006, The jCoderZ.org Project. All rights reserved.
5   *
6   * Redistribution and use in source and binary forms, with or without
7   * modification, are permitted provided that the following conditions are
8   * met:
9   *
10   *    * Redistributions of source code must retain the above copyright
11   *      notice, this list of conditions and the following disclaimer.
12   *    * Redistributions in binary form must reproduce the above
13   *      copyright notice, this list of conditions and the following
14   *      disclaimer in the documentation and/or other materials
15   *      provided with the distribution.
16   *    * Neither the name of the jCoderZ.org Project nor the names of
17   *      its contributors may be used to endorse or promote products
18   *      derived from this software without specific prior written
19   *      permission.
20   *
21   * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND
22   * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23   * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
24   * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS AND CONTRIBUTORS
25   * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
26   * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
27   * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
28   * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29   * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30   * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31   * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32   */
33  package org.jcoderz.phoenix.report;
34  
35  import java.io.File;
36  import java.io.FileNotFoundException;
37  import java.util.Arrays;
38  import java.util.Collection;
39  import java.util.Collections;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Map;
43  import java.util.logging.Logger;
44  
45  import javax.xml.bind.JAXBException;
46  
47  import org.jcoderz.phoenix.report.jaxb.Item;
48  
49  /**
50   * @author Michael Griffel
51   */
52  public final class SourceDirectoryReader
53        extends AbstractReportReader
54  {
550    private static final String CLASSNAME
56             = SourceDirectoryReader.class.getName();
57  
580    private static final Logger logger = Logger.getLogger(CLASSNAME);
59  
600    private final Map<ResourceInfo, List<Item>> mSources
61         = new HashMap<ResourceInfo, List<Item>>();
62     
63     /**
64      * This collection holds directory names that should never 
65      * contain any source files. 
66      **/
670(1)   private static final Collection<String> BLACKLISTED_DIR_NAMES
68         = Collections.unmodifiableCollection(
69             Arrays.asList(new String[] {".svn", "CVS"}));
70  
71     SourceDirectoryReader ()
72           throws JAXBException
73     {
740       super(JcoderzReport.JCODERZ_JAXB_CONTEXT_PATH);
750    }
76  
77     /** {@inheritDoc} */
78     protected Map<ResourceInfo, List<Item>> getItems ()
79           throws JAXBException
80     {
810       return Collections.unmodifiableMap(mSources);
82     }
83  
84     /** {@inheritDoc} */
85     public void parse (File f)
86           throws JAXBException, FileNotFoundException
87     {
880       if (! f.isDirectory())
89        {
900          throw new RuntimeException(
91               "The given source directory '" + f.getAbsolutePath()
92               + "' is not a valid directory.");
93        }
940       addSourceFiles(f, null, f.getAbsolutePath());
950    }
96  
97     private void addSourceFiles (File directory, String pkg, String sourceDir)
98     {
990       final File[] files = directory.listFiles();
1000       for (int i = 0; i < files.length; i++)
101        {
1020          final String resourceName = files[i].getAbsolutePath();
1030          if (files[i].isDirectory())
104           {
1050             if (BLACKLISTED_DIR_NAMES.contains(files[i].getName()))
106              {
1070                 logger.finer("Ignoring source dir: '" + files[i] + "'");
108              }
109              else
110              {
111                  final String subpkg;
1120                 if (pkg == null)
113                  {
1140                    subpkg = files[i].getName();
115                  }
116                  else
117                  {
1180                    subpkg = pkg + "." + files[i].getName();
119                  }
1200                 addSourceFiles(files[i], subpkg, sourceDir);
1210             }
122           }
123           else
124           {
1250             addResource(pkg, sourceDir, resourceName);
126           }
127        }
128        // register package.html if not already registered (only in **/src/java**)
1290       final String packageHtml
130            = directory.getAbsolutePath() + File.separator + "package.html";
1310       if (ResourceInfo.lookup(packageHtml) == null
132              && packageHtml.matches(".*/src/java.*"))
133        {
1340          ResourceInfo.register(packageHtml, pkg, sourceDir);
135        }
1360    }
137  
138     private void addResource (
139              String pkg, String sourceDir, final String resourceName)
140     {
1410       final ResourceInfo info
142              = ResourceInfo.register(resourceName, pkg, sourceDir);
1430(2)      mSources.put(info, Collections.EMPTY_LIST);
1440    }
145  }

Findings in this File

c (1) 67 : 4 Static variable definition in wrong order.
d (2) 143 : 37 [unchecked] unchecked conversion found : java.util.List required: java.util.List<org.jcoderz.phoenix.report.jaxb.Item>