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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 | package Torello.JavaDoc; import Torello.Java.*; import Torello.HTML.HTMLNode; import Torello.Java.ReadOnly.ReadOnlyList; import Torello.Java.ReadOnly.ROTreeMapBuilder; import Torello.Java.ReadOnly.ReadOnlyMap; import java.util.*; import java.io.*; import java.util.stream.Stream; /** * Retrieve Java Doc HTML Files from the Java Doc output directory. * * <BR /><BR /><EMBED CLASS='external-html' DATA-FILE-ID=JDFILES> */ @StaticFunctional public class JDFiles { private JDFiles() { } /** A Java {@code Predicate} that filters for {@code '.html'} files. */ public static final FilenameFilter HTML_FILE_FILTER = (File dir, String name) -> name.trim().endsWith(".html"); /** A Java {@code Predicate} that avoids directories that contain extranneous files. */ public static final FileFilter DIRS_TO_SKIP = (File dir) -> StrCmpr.equalsNAND (dir.getName(), "src-html", "index-files", "doc-files", "hilite-files" ); /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GJCHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #HTML_FILE_FILTER * @see #DIRS_TO_SKIP * @see FileNode * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ public static Stream<String> getJavaClassHTMLFiles(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .prune( (FileNode fn) -> StrCmpr.equalsNAND (fn.name, "package-summary.html", "package-tree.html", "package-frame.html"), true ) // This 'prune' eliminates HTML files in the *ROOT* Java-Doc directory .prune( (FileNode fn) -> ! rootJDOutDirName.equals(fn.getParentPathName()), true ) .flattenJustFiles(RTC.FULLPATH_STREAM()); } /** * This method returns the exact same files as {@link #getJavaClassHTMLFiles(String)}, but * each file returned <I>has been sorted into a specific 'bucket' based on which <B>Java * Package</B> the CIET (class, inteface, enumerated-type, record etc...) HTML file * belongs.</I> * * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * * @return This will return the list of files, sorted by 'Package Name' - where the package * is merely determined by the directory-name where the file was found. * * <BR /><TABLE CLASS=JDBriefTable> * * <TR><TH>Element</TH><TH>Contents</TH></TR> * * <TR> <TD>{@code ReadOnlyMap} 'key'</TD> * <TD>The <I>directory-name</I> of the Java-Doc HTML-Directory containing the CIET Java * Doc HTML Files for a specific package. (NOTE: This is different than the actual * 'Package Name') * </TD></TR> * * <TR> <TD>{@code ReadOnlyMap} 'value'</TD> * <TD>A {@code ReadOnlyList} of file-name's (each as a {@code String}) of each Java Doc * generated HTML file for a CIET in the specific package. * </TD></TR> * * </TABLE> * * @see #HTML_FILE_FILTER * @see #DIRS_TO_SKIP * @see FileNode * @see FileNode#getParentPathName() * @see FileNode#flattenJustDirs() */ public static ReadOnlyMap<String, ReadOnlyList<String>> getJavaClassHTMLFilesByPackage(String rootJDOutDirName) { // TreeMap<String, Vector<String>> ret = new TreeMap<>(); ROTreeMapBuilder<String, ReadOnlyList<String>> b = new ROTreeMapBuilder<>(); // These are files usually found in a Package-Directory. These cannot be processed by // the class "MainFilesProcessor". These files are not for CIET/Types (specific class // JD Files), but rather if/when these files need to be modified they are handled by the // "ExtraFilesProcessor" FileNodeFilter TYPE_HTML_FILES = (FileNode fn) -> StrCmpr.equalsNAND (fn.name, "package-summary.html", "package-tree.html", "package-frame.html"); FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .flattenJustDirs() .forEach((FileNode packageDirFN) -> { // The Full-Path Directory name of a single Java Package String packageDir = packageDirFN.getFullPathName(); // The root 'javadoc/' directory doesn't have any of the Java class files if (packageDir.equals(rootJDOutDirName)) return; // Retrieve all CIET/Type Web-Pages for a single package-directory ReadOnlyList<String> cietFileNames = packageDirFN.getDirContentsFiles (RTC.SORTED_FILENAME_ROAL(), TYPE_HTML_FILES); // Sometimes a Java-Package doesn't have any files in it. Skip those dirs. if (cietFileNames.size() > 0) b.put(packageDir, cietFileNames); }); return b.build(); } /* // NOTE: The original way of doing this was kind of stupid (but it did work!) FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .flattenJustFiles(RetTypeChoice.STREAM) .filter( (FileNode fn) -> StrCmpr.equalsNAND (fn.name, "package-summary.html", "package-tree.html", "package-frame.html")) // This 'prune' eliminates HTML files in the *ROOT* Java-Doc directory .filter((FileNode fn) -> ! rootJDOutDirName.equals(fn.getParentPathName())) .forEach((FileNode jdHTMLFile) -> { String packageDirectory = jdHTMLFile.getParentPathName(); Vector<String> packageFilesList = ret.get(packageDirectory); if (packageFilesList == null) ret.put(packageDirectory, packageFilesList = new Vector<>()); packageFilesList.add(jdHTMLFile.name); }); return ret; */ /** * Retrieves all User-Provided HTML Embed-Tag Map Files in his source-directory tree. * * @param rootSrcCodeDirName The root source-directory * @return All Externa-HTML {@code <EMBED>} Tag-to-FileName map files. * @see FileNode * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ @Deprecated public static Stream<String> allLocalEmbedTagMapFiles(String rootSrcCodeDirName) { return FileNode .createRoot(rootSrcCodeDirName) .loadTree( -1, (File dir, String fName) -> fName.equals("external-html-ids.properties"), null ) .flattenJustFiles(RTC.FULLPATH_STREAM()); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GSAHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #HTML_FILE_FILTER * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ public static Stream<String> getSrcAsHTMLFiles(String rootJDOutDirName) { if (! (new File(rootJDOutDirName + "src-html" + File.separator)).exists()) return Stream.empty(); return FileNode .createRoot(rootJDOutDirName + "src-html" + File.separator) .loadTree(-1, HTML_FILE_FILTER, null) .flattenJustFiles(RTC.FULLPATH_STREAM()); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GJPHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #HTML_FILE_FILTER * @see #DIRS_TO_SKIP * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ public static Stream<String> getJavaPackageHTMLFiles(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .flattenJustFiles(RTC.FULLPATH_STREAM()) .filter((String fileName) -> fileName.endsWith("package-summary.html") || fileName.endsWith("package-tree.html") || fileName.endsWith("package-frame.html") ); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_FRAMESUMM> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #HTML_FILE_FILTER * @see #DIRS_TO_SKIP * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ public static Stream<String> getFrameSummaryHTMLFiles(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .flattenJustFiles(RTC.FULLPATH_STREAM()) .filter((String fileName) -> fileName.endsWith("package-summary.html") || fileName.endsWith("package-frame.html") ); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GAHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #HTML_FILE_FILTER * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ public static Stream<String> getAllHTMLFiles(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) // The 'doc-files/' are user-generated, skip those... .loadTree(-1, HTML_FILE_FILTER, (File dir) -> (! dir.getName().equals("doc-files")) && (! dir.getName().equals("hilite-files")) ) .flattenJustFiles(RTC.FULLPATH_STREAM()); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GPSHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. */ public static Stream<String> getPackageSummaryHTMLFiles(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .flattenJustFiles(RTC.FULLPATH_STREAM()) .filter((String fileName) -> fileName.endsWith("package-summary.html")); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GPFHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. */ public static Stream<String> getPackageFrameHTMLFiles(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) .loadTree(-1, HTML_FILE_FILTER, DIRS_TO_SKIP) .flattenJustFiles(RTC.FULLPATH_STREAM()) .filter((String fileName) -> fileName.endsWith("package-frame.html")); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GHFIR> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #HTML_FILE_FILTER * @see FileNode#flattenJustFiles(RTC) * @see RTC#FULLPATH_STREAM() */ public static Stream<String> getHTMLFilesInRoot(String rootJDOutDirName) { return FileNode .createRoot(rootJDOutDirName) .loadTree(0, HTML_FILE_FILTER, null) .flattenJustFiles(RTC.FULLPATH_STREAM()); } /** * <EMBED CLASS='external-html' DATA-FILE-ID=JDF_GPTHF> * @param rootJDOutDirName <EMBED CLASS='external-html' DATA-FILE-ID=JDF_ROOT> * @return This will return the list of files as a Java {@code Stream<String>}. * @see #getJavaPackageHTMLFiles(String) */ public static Stream<String> getPackageTreeHTMLFiles(String rootJDOutDirName) { return JDFiles .getJavaPackageHTMLFiles(rootJDOutDirName) .filter((String fileName) -> fileName.contains("package-tree.html")); } } |