diff options
author | Scott Main <smain@google.com> | 2013-04-10 17:57:58 -0700 |
---|---|---|
committer | Android Git Automerger <android-git-automerger@android.com> | 2013-04-10 17:57:58 -0700 |
commit | 08f154f1c281115bd86c6ea4a2214177e2372732 (patch) | |
tree | ed0667abeba80e7f5f93118ae1aa53969e8638fc | |
parent | 92f56c6130ce2f0358dfde8ea41450c8767402be (diff) | |
parent | 71bf8d2ae787c28691910bb228a5d9efca9b153d (diff) | |
download | android_external_doclava-08f154f1c281115bd86c6ea4a2214177e2372732.tar.gz android_external_doclava-08f154f1c281115bd86c6ea4a2214177e2372732.tar.bz2 android_external_doclava-08f154f1c281115bd86c6ea4a2214177e2372732.zip |
am 71bf8d2a: add logic to doclava to generate meta-data JSON for .jd files. This will be used to provide search suggestions for all docs, and also automated "see also" links in doc TOC for pages w/ matching tags
* commit '71bf8d2ae787c28691910bb228a5d9efca9b153d':
add logic to doclava to generate meta-data JSON for .jd files. This will be used to provide search suggestions for all docs, and also automated "see also" links in doc TOC for pages w/ matching tags
-rw-r--r-- | res/assets/templates/jd_lists.cs | 8 | ||||
-rw-r--r-- | src/com/google/doclava/DocFile.java | 4 | ||||
-rw-r--r-- | src/com/google/doclava/Doclava.java | 84 |
3 files changed, 93 insertions, 3 deletions
diff --git a/res/assets/templates/jd_lists.cs b/res/assets/templates/jd_lists.cs new file mode 100644 index 0000000..e205032 --- /dev/null +++ b/res/assets/templates/jd_lists.cs @@ -0,0 +1,8 @@ +var JD_DATA = [ +<?cs +each:page = docs.pages +?> + { label:"<?cs var:page.label ?>", link:"<?cs var:page.link ?>", + tags:[<?cs var:page.tags ?>], type:"<?cs var:page.type ?>" }<?cs if:!last(page) ?>,<?cs /if ?><?cs +/each ?> +]; diff --git a/src/com/google/doclava/DocFile.java b/src/com/google/doclava/DocFile.java index dd0a6bc..9e56235 100644 --- a/src/com/google/doclava/DocFile.java +++ b/src/com/google/doclava/DocFile.java @@ -24,8 +24,8 @@ import java.util.regex.Matcher; public class DocFile { - private static final Pattern LINE = Pattern.compile("(.*)[\r]?\n", Pattern.MULTILINE); - private static final Pattern PROP = Pattern.compile("([^=]+)=(.*)"); + public static final Pattern LINE = Pattern.compile("(.*)[\r]?\n", Pattern.MULTILINE); + public static final Pattern PROP = Pattern.compile("([^=]+)=(.*)"); public static String readFile(String filename) { try { diff --git a/src/com/google/doclava/Doclava.java b/src/com/google/doclava/Doclava.java index a239210..33f68c0 100644 --- a/src/com/google/doclava/Doclava.java +++ b/src/com/google/doclava/Doclava.java @@ -27,6 +27,7 @@ import com.sun.javadoc.*; import java.util.*; import java.util.jar.JarFile; +import java.util.regex.Matcher; import java.io.*; import java.lang.reflect.Proxy; import java.lang.reflect.Array; @@ -792,7 +793,11 @@ public class Doclava { ClearPage.write(timedata, "timestamp.cs", "timestamp.js"); } + /** Go through the docs and generate meta-data about each + page to use in search suggestions */ public static void writeLists() { + + // Write the lists for API references Data data = makeHDF(); ClassInfo[] classes = Converter.rootClasses(); @@ -830,8 +835,85 @@ public class Doclava { } i++; } - ClearPage.write(data, "lists.cs", javadocDir + "lists.js"); + + + // Write the lists for JD documents + Data jddata = makeHDF(); + Iterator counter = new Iterator(); + for (String htmlDir : inputPathHtmlDirs) { + File dir = new File(htmlDir); + if (!dir.isDirectory()) { + continue; + } + writeJdDirList(dir, jddata, counter); + } + ClearPage.write(jddata, "jd_lists.cs", javadocDir + "jd_lists.js"); + } + + private static class Iterator { + int i = 0; + } + + /** Write meta-data for a JD file, used for search suggestions */ + private static void writeJdDirList(File dir, Data data, Iterator counter) { + File[] files = dir.listFiles(); + int i, count = files.length; + // Loop all files in given directory + for (i = 0; i < count; i++) { + File f = files[i]; + if (f.isFile()) { + String filePath = f.getAbsolutePath(); + String templ = f.getName(); + int len = templ.length(); + // If it's a .jd file we want to process + if (len > 3 && ".jd".equals(templ.substring(len - 3))) { + // remove the directories below the site root + String webPath = filePath.substring(filePath.indexOf("docs/html/") + 10, filePath.length()); + // replace .jd with .html + webPath = webPath.substring(0, webPath.length() - 3) + htmlExtension; + // Parse the .jd file for properties data at top of page + Data hdf = Doclava.makeHDF(); + String filedata = DocFile.readFile(filePath); + Matcher lines = DocFile.LINE.matcher(filedata); + String line = null; + // Get each line to add the key-value to hdf + while (lines.find()) { + line = lines.group(1); + if (line.length() > 0) { + // Stop when we hit the body + if (line.equals("@jd:body")) { + break; + } + Matcher prop = DocFile.PROP.matcher(line); + if (prop.matches()) { + String key = prop.group(1); + String value = prop.group(2); + hdf.setValue(key, value); + } else { + break; + } + } + } // done gathering page properties + + // Insert the goods into HDF data (title, link, tags, type) + String title = hdf.getValue("page.title", ""); + String tags = hdf.getValue("page.tags", ""); + String dirName = (webPath.indexOf("/") != -1) + ? webPath.substring(0, webPath.indexOf("/")) : ""; + + if (!"".equals(title) && !"intl".equals(dirName)) { + data.setValue("docs.pages." + counter.i + ".label", title.replaceAll("\"", "'")); + data.setValue("docs.pages." + counter.i + ".link", webPath); + data.setValue("docs.pages." + counter.i + ".tags", tags); + data.setValue("docs.pages." + counter.i + ".type", dirName); + counter.i++; + } + } + } else if (f.isDirectory()) { + writeJdDirList(f, data, counter); + } + } } public static void cantStripThis(ClassInfo cl, HashSet<ClassInfo> notStrippable) { |