| 1 | | | |
| 2 | | | |
| 3 | | | |
| 4 | | | |
| 5 | | | |
| 6 | | | |
| 7 | | | |
| 8 | | | |
| 9 | | | |
| 10 | | | |
| 11 | | | |
| 12 | | | |
| 13 | | | |
| 14 | | | |
| 15 | | | |
| 16 | | | |
| 17 | | | |
| 18 | | | |
| 19 | | | |
| 20 | | | |
| 21 | | | |
| 22 | | | |
| 23 | | | |
| 24 | | | |
| 25 | | | |
| 26 | | | |
| 27 | | | |
| 28 | | | |
| 29 | | | |
| 30 | | | |
| 31 | | | |
| 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 |
| 51 | | | |
| 52 | | | public final class SourceDirectoryReader |
| 53 | | | extends AbstractReportReader |
| 54 | | | { |
| 55 | 0 | | private static final String CLASSNAME |
| 56 | | | = SourceDirectoryReader.class.getName(); |
| 57 | | | |
| 58 | 0 | | private static final Logger logger = Logger.getLogger(CLASSNAME); |
| 59 | | | |
| 60 | 0 | | private final Map<ResourceInfo, List<Item>> mSources |
| 61 | | | = new HashMap<ResourceInfo, List<Item>>(); |
| 62 | | | |
| 63 | | | |
| 64 | | | |
| 65 | | | |
| 66 | | | |
| 67 | 0 | (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 | | | { |
| 74 | 0 | | super(JcoderzReport.JCODERZ_JAXB_CONTEXT_PATH); |
| 75 | 0 | | } |
| 76 | | | |
| 77 | | | {@inheritDoc} |
| 78 | | | protected Map<ResourceInfo, List<Item>> getItems () |
| 79 | | | throws JAXBException |
| 80 | | | { |
| 81 | 0 | | return Collections.unmodifiableMap(mSources); |
| 82 | | | } |
| 83 | | | |
| 84 | | | {@inheritDoc} |
| 85 | | | public void parse (File f) |
| 86 | | | throws JAXBException, FileNotFoundException |
| 87 | | | { |
| 88 | 0 | | if (! f.isDirectory()) |
| 89 | | | { |
| 90 | 0 | | throw new RuntimeException( |
| 91 | | | "The given source directory '" + f.getAbsolutePath() |
| 92 | | | + "' is not a valid directory."); |
| 93 | | | } |
| 94 | 0 | | addSourceFiles(f, null, f.getAbsolutePath()); |
| 95 | 0 | | } |
| 96 | | | |
| 97 | | | private void addSourceFiles (File directory, String pkg, String sourceDir) |
| 98 | | | { |
| 99 | 0 | | final File[] files = directory.listFiles(); |
| 100 | 0 | | for (int i = 0; i < files.length; i++) |
| 101 | | | { |
| 102 | 0 | | final String resourceName = files[i].getAbsolutePath(); |
| 103 | 0 | | if (files[i].isDirectory()) |
| 104 | | | { |
| 105 | 0 | | if (BLACKLISTED_DIR_NAMES.contains(files[i].getName())) |
| 106 | | | { |
| 107 | 0 | | logger.finer("Ignoring source dir: '" + files[i] + "'"); |
| 108 | | | } |
| 109 | | | else |
| 110 | | | { |
| 111 | | | final String subpkg; |
| 112 | 0 | | if (pkg == null) |
| 113 | | | { |
| 114 | 0 | | subpkg = files[i].getName(); |
| 115 | | | } |
| 116 | | | else |
| 117 | | | { |
| 118 | 0 | | subpkg = pkg + "." + files[i].getName(); |
| 119 | | | } |
| 120 | 0 | | addSourceFiles(files[i], subpkg, sourceDir); |
| 121 | 0 | | } |
| 122 | | | } |
| 123 | | | else |
| 124 | | | { |
| 125 | 0 | | addResource(pkg, sourceDir, resourceName); |
| 126 | | | } |
| 127 | | | } |
| 128 | | | |
| 129 | 0 | | final String packageHtml |
| 130 | | | = directory.getAbsolutePath() + File.separator + "package.html"; |
| 131 | 0 | | if (ResourceInfo.lookup(packageHtml) == null |
| 132 | | | && packageHtml.matches(".*/src/java.*")) |
| 133 | | | { |
| 134 | 0 | | ResourceInfo.register(packageHtml, pkg, sourceDir); |
| 135 | | | } |
| 136 | 0 | | } |
| 137 | | | |
| 138 | | | private void addResource ( |
| 139 | | | String pkg, String sourceDir, final String resourceName) |
| 140 | | | { |
| 141 | 0 | | final ResourceInfo info |
| 142 | | | = ResourceInfo.register(resourceName, pkg, sourceDir); |
| 143 | 0 | (2) | mSources.put(info, Collections.EMPTY_LIST); |
| 144 | 0 | | } |
| 145 | | | } |