Merge "Show all licenses when multiple." am: 3c2639ac70
Change-Id: I3f9775de6b9be78c933ff7b07a19b1817d2f0f67
This commit is contained in:
@@ -35,8 +35,10 @@ import java.io.PrintWriter;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
import java.util.zip.GZIPInputStream;
|
import java.util.zip.GZIPInputStream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -84,7 +86,7 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
* "9645f39e9db895a4aa6e02cb57294595". Here "9645f39e9db895a4aa6e02cb57294595" is a MD5 sum
|
* "9645f39e9db895a4aa6e02cb57294595". Here "9645f39e9db895a4aa6e02cb57294595" is a MD5 sum
|
||||||
* of the content of packages/services/Telephony/MODULE_LICENSE_APACHE2.
|
* of the content of packages/services/Telephony/MODULE_LICENSE_APACHE2.
|
||||||
*/
|
*/
|
||||||
private final Map<String, String> mFileNameToContentIdMap = new HashMap();
|
private final Map<String, Set<String>> mFileNameToContentIdMap = new HashMap();
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* A map from a content id (MD5 sum of file content) to a license file content.
|
* A map from a content id (MD5 sum of file content) to a license file content.
|
||||||
@@ -186,10 +188,10 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
* </licenses>
|
* </licenses>
|
||||||
*/
|
*/
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void parse(InputStreamReader in, Map<String, String> outFileNameToContentIdMap,
|
static void parse(InputStreamReader in, Map<String, Set<String>> outFileNameToContentIdMap,
|
||||||
Map<String, String> outContentIdToFileContentMap)
|
Map<String, String> outContentIdToFileContentMap)
|
||||||
throws XmlPullParserException, IOException {
|
throws XmlPullParserException, IOException {
|
||||||
Map<String, String> fileNameToContentIdMap = new HashMap<String, String>();
|
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<String, Set<String>>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<String, String>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<String, String>();
|
||||||
|
|
||||||
XmlPullParser parser = Xml.newPullParser();
|
XmlPullParser parser = Xml.newPullParser();
|
||||||
@@ -206,7 +208,10 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
if (!TextUtils.isEmpty(contentId)) {
|
if (!TextUtils.isEmpty(contentId)) {
|
||||||
String fileName = readText(parser).trim();
|
String fileName = readText(parser).trim();
|
||||||
if (!TextUtils.isEmpty(fileName)) {
|
if (!TextUtils.isEmpty(fileName)) {
|
||||||
fileNameToContentIdMap.put(fileName, contentId);
|
Set<String> contentIds =
|
||||||
|
fileNameToContentIdMap.computeIfAbsent(
|
||||||
|
fileName, k -> new HashSet<>());
|
||||||
|
contentIds.add(contentId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if (TAG_FILE_CONTENT.equals(parser.getName())) {
|
} else if (TAG_FILE_CONTENT.equals(parser.getName())) {
|
||||||
@@ -224,7 +229,13 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
|
|
||||||
state = parser.next();
|
state = parser.next();
|
||||||
}
|
}
|
||||||
outFileNameToContentIdMap.putAll(fileNameToContentIdMap);
|
for (Map.Entry<String, Set<String>> entry : fileNameToContentIdMap.entrySet()) {
|
||||||
|
outFileNameToContentIdMap.merge(
|
||||||
|
entry.getKey(), entry.getValue(), (s1, s2) -> {
|
||||||
|
s1.addAll(s2);
|
||||||
|
return s1;
|
||||||
|
});
|
||||||
|
}
|
||||||
outContentIdToFileContentMap.putAll(contentIdToFileContentMap);
|
outContentIdToFileContentMap.putAll(contentIdToFileContentMap);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -240,7 +251,7 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@VisibleForTesting
|
@VisibleForTesting
|
||||||
static void generateHtml(Map<String, String> fileNameToContentIdMap,
|
static void generateHtml(Map<String, Set<String>> fileNameToContentIdMap,
|
||||||
Map<String, String> contentIdToFileContentMap, PrintWriter writer,
|
Map<String, String> contentIdToFileContentMap, PrintWriter writer,
|
||||||
String noticeHeader) {
|
String noticeHeader) {
|
||||||
List<String> fileNameList = new ArrayList();
|
List<String> fileNameList = new ArrayList();
|
||||||
@@ -259,7 +270,7 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
|
|
||||||
// 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) {
|
||||||
String contentId = fileNameToContentIdMap.get(fileName);
|
for (String contentId : fileNameToContentIdMap.get(fileName)) {
|
||||||
// Assigns an id to a newly referred license file content.
|
// Assigns an id to a newly referred license file content.
|
||||||
if (!contentIdToOrderMap.containsKey(contentId)) {
|
if (!contentIdToOrderMap.containsKey(contentId)) {
|
||||||
contentIdToOrderMap.put(contentId, count);
|
contentIdToOrderMap.put(contentId, count);
|
||||||
@@ -273,6 +284,7 @@ class LicenseHtmlGeneratorFromXml {
|
|||||||
contentIdAndFileNamesList.get(id).mFileNameList.add(fileName);
|
contentIdAndFileNamesList.get(id).mFileNameList.add(fileName);
|
||||||
writer.format("<li><a href=\"#id%d\">%s</a></li>\n", id, fileName);
|
writer.format("<li><a href=\"#id%d\">%s</a></li>\n", id, fileName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
writer.println(HTML_MIDDLE_STRING);
|
writer.println(HTML_MIDDLE_STRING);
|
||||||
|
|
||||||
|
|||||||
@@ -28,8 +28,11 @@ 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.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.HashSet;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Set;
|
||||||
|
|
||||||
@RunWith(RobolectricTestRunner.class)
|
@RunWith(RobolectricTestRunner.class)
|
||||||
public class LicenseHtmlGeneratorFromXmlTest {
|
public class LicenseHtmlGeneratorFromXmlTest {
|
||||||
@@ -68,6 +71,7 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
private static final String HTML_BODY_STRING =
|
private static final String HTML_BODY_STRING =
|
||||||
"<li><a href=\"#id0\">/file0</a></li>\n"
|
"<li><a href=\"#id0\">/file0</a></li>\n"
|
||||||
|
+ "<li><a href=\"#id1\">/file0</a></li>\n"
|
||||||
+ "<li><a href=\"#id0\">/file1</a></li>\n"
|
+ "<li><a href=\"#id0\">/file1</a></li>\n"
|
||||||
+ "</ul>\n"
|
+ "</ul>\n"
|
||||||
+ "</div><!-- table of contents -->\n"
|
+ "</div><!-- table of contents -->\n"
|
||||||
@@ -82,6 +86,15 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
+ "license content #0\n"
|
+ "license content #0\n"
|
||||||
+ "</pre><!-- license-text -->\n"
|
+ "</pre><!-- license-text -->\n"
|
||||||
+ "</td></tr><!-- same-license -->\n"
|
+ "</td></tr><!-- same-license -->\n"
|
||||||
|
+ "<tr id=\"id1\"><td class=\"same-license\">\n"
|
||||||
|
+ "<div class=\"label\">Notices for file(s):</div>\n"
|
||||||
|
+ "<div class=\"file-list\">\n"
|
||||||
|
+ "/file0 <br/>\n"
|
||||||
|
+ "</div><!-- file-list -->\n"
|
||||||
|
+ "<pre class=\"license-text\">\n"
|
||||||
|
+ "license content #1\n"
|
||||||
|
+ "</pre><!-- license-text -->\n"
|
||||||
|
+ "</td></tr><!-- same-license -->\n"
|
||||||
+ "</table></body></html>\n";
|
+ "</table></body></html>\n";
|
||||||
|
|
||||||
private static final String EXPECTED_HTML_STRING = HTML_HEAD_STRING + HTML_BODY_STRING;
|
private static final String EXPECTED_HTML_STRING = HTML_HEAD_STRING + HTML_BODY_STRING;
|
||||||
@@ -91,22 +104,22 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParseValidXmlStream() throws XmlPullParserException, IOException {
|
public void testParseValidXmlStream() throws XmlPullParserException, IOException {
|
||||||
Map<String, String> fileNameToContentIdMap = new HashMap<>();
|
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
|
|
||||||
LicenseHtmlGeneratorFromXml.parse(
|
LicenseHtmlGeneratorFromXml.parse(
|
||||||
new InputStreamReader(new ByteArrayInputStream(VALILD_XML_STRING.getBytes())),
|
new InputStreamReader(new ByteArrayInputStream(VALILD_XML_STRING.getBytes())),
|
||||||
fileNameToContentIdMap, contentIdToFileContentMap);
|
fileNameToContentIdMap, contentIdToFileContentMap);
|
||||||
assertThat(fileNameToContentIdMap.size()).isEqualTo(2);
|
assertThat(fileNameToContentIdMap.size()).isEqualTo(2);
|
||||||
assertThat(fileNameToContentIdMap.get("/file0")).isEqualTo("0");
|
assertThat(fileNameToContentIdMap.get("/file0")).containsExactly("0");
|
||||||
assertThat(fileNameToContentIdMap.get("/file1")).isEqualTo("0");
|
assertThat(fileNameToContentIdMap.get("/file1")).containsExactly("0");
|
||||||
assertThat(contentIdToFileContentMap.size()).isEqualTo(1);
|
assertThat(contentIdToFileContentMap.size()).isEqualTo(1);
|
||||||
assertThat(contentIdToFileContentMap.get("0")).isEqualTo("license content #0");
|
assertThat(contentIdToFileContentMap.get("0")).isEqualTo("license content #0");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = XmlPullParserException.class)
|
@Test(expected = XmlPullParserException.class)
|
||||||
public void testParseInvalidXmlStream() throws XmlPullParserException, IOException {
|
public void testParseInvalidXmlStream() throws XmlPullParserException, IOException {
|
||||||
Map<String, String> fileNameToContentIdMap = new HashMap<>();
|
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
|
|
||||||
LicenseHtmlGeneratorFromXml.parse(
|
LicenseHtmlGeneratorFromXml.parse(
|
||||||
@@ -116,12 +129,13 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateHtml() {
|
public void testGenerateHtml() {
|
||||||
Map<String, String> fileNameToContentIdMap = new HashMap<>();
|
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
|
|
||||||
fileNameToContentIdMap.put("/file0", "0");
|
fileNameToContentIdMap.put("/file0", new HashSet<String>(Arrays.asList("0", "1")));
|
||||||
fileNameToContentIdMap.put("/file1", "0");
|
fileNameToContentIdMap.put("/file1", new HashSet<String>(Arrays.asList("0")));
|
||||||
contentIdToFileContentMap.put("0", "license content #0");
|
contentIdToFileContentMap.put("0", "license content #0");
|
||||||
|
contentIdToFileContentMap.put("1", "license content #1");
|
||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
@@ -131,12 +145,13 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGenerateHtmlWithCustomHeading() {
|
public void testGenerateHtmlWithCustomHeading() {
|
||||||
Map<String, String> fileNameToContentIdMap = new HashMap<>();
|
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||||
|
|
||||||
fileNameToContentIdMap.put("/file0", "0");
|
fileNameToContentIdMap.put("/file0", new HashSet<String>(Arrays.asList("0", "1")));
|
||||||
fileNameToContentIdMap.put("/file1", "0");
|
fileNameToContentIdMap.put("/file1", new HashSet<String>(Arrays.asList("0")));
|
||||||
contentIdToFileContentMap.put("0", "license content #0");
|
contentIdToFileContentMap.put("0", "license content #0");
|
||||||
|
contentIdToFileContentMap.put("1", "license content #1");
|
||||||
|
|
||||||
StringWriter output = new StringWriter();
|
StringWriter output = new StringWriter();
|
||||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||||
|
|||||||
Reference in New Issue
Block a user