Merge "Add stats to notice UI." am: 1db210c09c
Original change: https://android-review.googlesource.com/c/platform/frameworks/base/+/2180037 Change-Id: I9e740ea835c74d0f0d57369384ae540cf83a2f18 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
@@ -27,7 +27,6 @@ import org.xmlpull.v1.XmlPullParserException;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
@@ -76,14 +75,22 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
private static final String LIBRARY_TAIL_STRING = "</ul>\n<strong>Files</strong>";
|
private static final String LIBRARY_TAIL_STRING = "</ul>\n<strong>Files</strong>";
|
||||||
|
|
||||||
private static final String FILES_HEAD_STRING = "<ul class=\"files\">";
|
private static final String FILES_HEAD_STRING = "<ul class=\"files\">";
|
||||||
|
private static final String FILES_TAIL_STRING = "</ul>\n</div><!-- table of contents -->";
|
||||||
|
|
||||||
private static final String HTML_MIDDLE_STRING =
|
private static final String CONTENT_HEAD_STRING =
|
||||||
"</ul>\n"
|
"<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
|
||||||
+ "</div><!-- table of contents -->\n"
|
private static final String CONTENT_TAIL_STRING = "</table>";
|
||||||
+ "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">";
|
|
||||||
|
|
||||||
private static final String HTML_REAR_STRING =
|
private static final String IMAGES_HEAD_STRING =
|
||||||
"</table></body></html>";
|
"<div class=\"images-list\"><strong>Images</strong>\n<ul class=\"images\">";
|
||||||
|
private static final String IMAGES_TAIL_STRING = "</ul></div>\n";
|
||||||
|
|
||||||
|
private static final String PATH_COUNTS_HEAD_STRING =
|
||||||
|
"<div class=\"path-counts\"><table>\n <tr><th>Path prefix</th><th>Count</th></tr>\n";
|
||||||
|
private static final String PATH_COUNTS_TAIL_STRING = "</table></div>\n";
|
||||||
|
|
||||||
|
private static final String HTML_TAIL_STRING =
|
||||||
|
"</body></html>";
|
||||||
|
|
||||||
private final List<File> mXmlFiles;
|
private final List<File> mXmlFiles;
|
||||||
|
|
||||||
@@ -137,13 +144,13 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
try {
|
try {
|
||||||
writer = new PrintWriter(outputFile);
|
writer = new PrintWriter(outputFile);
|
||||||
|
|
||||||
generateHtml(mFileNameToLibraryToContentIdMap, mContentIdToFileContentMap, writer,
|
generateHtml(mXmlFiles, mFileNameToLibraryToContentIdMap, mContentIdToFileContentMap,
|
||||||
noticeHeader);
|
writer, noticeHeader);
|
||||||
|
|
||||||
writer.flush();
|
writer.flush();
|
||||||
writer.close();
|
writer.close();
|
||||||
return true;
|
return true;
|
||||||
} catch (FileNotFoundException | SecurityException e) {
|
} catch (IOException | SecurityException e) {
|
||||||
Log.e(TAG, "Failed to generate " + outputFile, e);
|
Log.e(TAG, "Failed to generate " + outputFile, e);
|
||||||
|
|
||||||
if (writer != null) {
|
if (writer != null) {
|
||||||
@@ -271,14 +278,33 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
return result.toString();
|
return result.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String pathPrefix(String path) {
|
||||||
|
String prefix = path;
|
||||||
|
while (prefix.length() > 0 && prefix.substring(0, 1).equals("/")) {
|
||||||
|
prefix = prefix.substring(1);
|
||||||
|
}
|
||||||
|
int idx = prefix.indexOf("/");
|
||||||
|
if (idx > 0) {
|
||||||
|
prefix = prefix.substring(0, idx);
|
||||||
|
}
|
||||||
|
return prefix;
|
||||||
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void generateHtml(Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap,
|
static void generateHtml(List<File> xmlFiles,
|
||||||
|
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap,
|
||||||
Map<String, String> contentIdToFileContentMap, PrintWriter writer,
|
Map<String, String> contentIdToFileContentMap, PrintWriter writer,
|
||||||
String noticeHeader) {
|
String noticeHeader) throws IOException {
|
||||||
List<String> fileNameList = new ArrayList();
|
List<String> fileNameList = new ArrayList();
|
||||||
fileNameList.addAll(fileNameToLibraryToContentIdMap.keySet());
|
fileNameList.addAll(fileNameToLibraryToContentIdMap.keySet());
|
||||||
Collections.sort(fileNameList);
|
Collections.sort(fileNameList);
|
||||||
|
|
||||||
|
SortedMap<String, Integer> prefixToCount = new TreeMap();
|
||||||
|
for (String f : fileNameList) {
|
||||||
|
String prefix = pathPrefix(f);
|
||||||
|
prefixToCount.merge(prefix, 1, Integer::sum);
|
||||||
|
}
|
||||||
|
|
||||||
SortedMap<String, Set<String>> libraryToContentIdMap = new TreeMap();
|
SortedMap<String, Set<String>> libraryToContentIdMap = new TreeMap();
|
||||||
for (Map<String, Set<String>> libraryToContentValue :
|
for (Map<String, Set<String>> libraryToContentValue :
|
||||||
fileNameToLibraryToContentIdMap.values()) {
|
fileNameToLibraryToContentIdMap.values()) {
|
||||||
@@ -324,8 +350,8 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
writer.println(LIBRARY_TAIL_STRING);
|
writer.println(LIBRARY_TAIL_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!fileNameList.isEmpty()) {
|
||||||
writer.println(FILES_HEAD_STRING);
|
writer.println(FILES_HEAD_STRING);
|
||||||
|
|
||||||
// Prints all the file list with a link to its license file content.
|
// Prints all the file list with a link to its license file content.
|
||||||
for (String fileName : fileNameList) {
|
for (String fileName : fileNameList) {
|
||||||
for (Map.Entry<String, Set<String>> libToContentId :
|
for (Map.Entry<String, Set<String>> libToContentId :
|
||||||
@@ -358,9 +384,11 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
writer.println(FILES_TAIL_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
writer.println(HTML_MIDDLE_STRING);
|
if (!contentIdAndFileNamesList.isEmpty()) {
|
||||||
|
writer.println(CONTENT_HEAD_STRING);
|
||||||
// Prints all contents of the license files in order of id.
|
// Prints all contents of the license files in order of id.
|
||||||
for (ContentIdAndFileNames contentIdAndFileNames : contentIdAndFileNamesList) {
|
for (ContentIdAndFileNames contentIdAndFileNames : contentIdAndFileNamesList) {
|
||||||
// Assigns an id to a newly referred license file content (should never happen here)
|
// Assigns an id to a newly referred license file content (should never happen here)
|
||||||
@@ -391,7 +419,26 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
writer.println("</pre><!-- license-text -->");
|
writer.println("</pre><!-- license-text -->");
|
||||||
writer.println("</td></tr><!-- same-license -->");
|
writer.println("</td></tr><!-- same-license -->");
|
||||||
}
|
}
|
||||||
|
writer.println(CONTENT_TAIL_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
writer.println(HTML_REAR_STRING);
|
if (!xmlFiles.isEmpty()) {
|
||||||
|
writer.println(IMAGES_HEAD_STRING);
|
||||||
|
for (File file : xmlFiles) {
|
||||||
|
writer.format(" <li>%s</li>\n", pathPrefix(file.getCanonicalPath()));
|
||||||
|
}
|
||||||
|
writer.println(IMAGES_TAIL_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!prefixToCount.isEmpty()) {
|
||||||
|
writer.println(PATH_COUNTS_HEAD_STRING);
|
||||||
|
for (Map.Entry<String, Integer> entry : prefixToCount.entrySet()) {
|
||||||
|
writer.format(" <tr><td>%s</td><td>%d</td></tr>\n",
|
||||||
|
entry.getKey(), entry.getValue());
|
||||||
|
}
|
||||||
|
writer.println(PATH_COUNTS_TAIL_STRING);
|
||||||
|
}
|
||||||
|
|
||||||
|
writer.println(HTML_TAIL_STRING);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -24,13 +24,16 @@ import org.robolectric.RobolectricTestRunner;
|
|||||||
import org.xmlpull.v1.XmlPullParserException;
|
import org.xmlpull.v1.XmlPullParserException;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.PrintWriter;
|
import java.io.PrintWriter;
|
||||||
import java.io.StringWriter;
|
import java.io.StringWriter;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@@ -202,7 +205,8 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateHtml() {
|
public void testGenerateHtml() throws Exception {
|
||||||
|
List<File> xmlFiles = new ArrayList<>();
|
||||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||||
@@ -218,13 +222,14 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
xmlFiles, fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||||
new PrintWriter(output), "");
|
new PrintWriter(output), "");
|
||||||
assertThat(output.toString()).isEqualTo(EXPECTED_OLD_HTML_STRING);
|
assertThat(output.toString()).isEqualTo(EXPECTED_OLD_HTML_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateNewHtml() {
|
public void testGenerateNewHtml() throws Exception {
|
||||||
|
List<File> xmlFiles = new ArrayList<>();
|
||||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||||
@@ -244,13 +249,14 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
xmlFiles, fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||||
new PrintWriter(output), "");
|
new PrintWriter(output), "");
|
||||||
assertThat(output.toString()).isEqualTo(EXPECTED_NEW_HTML_STRING);
|
assertThat(output.toString()).isEqualTo(EXPECTED_NEW_HTML_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateHtmlWithCustomHeading() {
|
public void testGenerateHtmlWithCustomHeading() throws Exception {
|
||||||
|
List<File> xmlFiles = new ArrayList<>();
|
||||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||||
@@ -266,13 +272,14 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
xmlFiles, fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||||
new PrintWriter(output), HTML_CUSTOM_HEADING);
|
new PrintWriter(output), HTML_CUSTOM_HEADING);
|
||||||
assertThat(output.toString()).isEqualTo(EXPECTED_OLD_HTML_STRING_WITH_CUSTOM_HEADING);
|
assertThat(output.toString()).isEqualTo(EXPECTED_OLD_HTML_STRING_WITH_CUSTOM_HEADING);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateNewHtmlWithCustomHeading() {
|
public void testGenerateNewHtmlWithCustomHeading() throws Exception {
|
||||||
|
List<File> xmlFiles = new ArrayList<>();
|
||||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||||
@@ -292,7 +299,7 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
xmlFiles, fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||||
new PrintWriter(output), HTML_CUSTOM_HEADING);
|
new PrintWriter(output), HTML_CUSTOM_HEADING);
|
||||||
assertThat(output.toString()).isEqualTo(EXPECTED_NEW_HTML_STRING_WITH_CUSTOM_HEADING);
|
assertThat(output.toString()).isEqualTo(EXPECTED_NEW_HTML_STRING_WITH_CUSTOM_HEADING);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user