Merge "Add support for library names."
This commit is contained in:
commit
11f3b36c61
@ -39,6 +39,8 @@ import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.SortedMap;
|
||||
import java.util.TreeMap;
|
||||
import java.util.zip.GZIPInputStream;
|
||||
|
||||
/**
|
||||
@ -54,6 +56,7 @@ class LicenseHtmlGeneratorFromXml {
|
||||
private static final String TAG_FILE_NAME = "file-name";
|
||||
private static final String TAG_FILE_CONTENT = "file-content";
|
||||
private static final String ATTR_CONTENT_ID = "contentId";
|
||||
private static final String ATTR_LIBRARY_NAME = "lib";
|
||||
|
||||
private static final String HTML_HEAD_STRING =
|
||||
"<html><head>\n"
|
||||
@ -67,8 +70,12 @@ class LicenseHtmlGeneratorFromXml {
|
||||
+ "</style>\n"
|
||||
+ "</head>"
|
||||
+ "<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">\n"
|
||||
+ "<div class=\"toc\">\n"
|
||||
+ "<ul>";
|
||||
+ "<div class=\"toc\">\n";
|
||||
private static final String LIBRARY_HEAD_STRING =
|
||||
"<strong>Libraries</strong>\n<ul class=\"libraries\">";
|
||||
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 HTML_MIDDLE_STRING =
|
||||
"</ul>\n"
|
||||
@ -81,12 +88,14 @@ class LicenseHtmlGeneratorFromXml {
|
||||
private final List<File> mXmlFiles;
|
||||
|
||||
/*
|
||||
* A map from a file name to a content id (MD5 sum of file content) for its license.
|
||||
* For example, "/system/priv-app/TeleService/TeleService.apk" maps to
|
||||
* A map from a file name to a library name (may be empty) to a content id (MD5 sum of file
|
||||
* content) for its license.
|
||||
* For example, "/system/priv-app/TeleService/TeleService.apk" maps to "service/Telephony" to
|
||||
* "9645f39e9db895a4aa6e02cb57294595". Here "9645f39e9db895a4aa6e02cb57294595" is a MD5 sum
|
||||
* of the content of packages/services/Telephony/MODULE_LICENSE_APACHE2.
|
||||
*/
|
||||
private final Map<String, Set<String>> mFileNameToContentIdMap = new HashMap();
|
||||
private final Map<String, Map<String, Set<String>>> mFileNameToLibraryToContentIdMap =
|
||||
new HashMap();
|
||||
|
||||
/*
|
||||
* A map from a content id (MD5 sum of file content) to a license file content.
|
||||
@ -98,7 +107,7 @@ class LicenseHtmlGeneratorFromXml {
|
||||
|
||||
static class ContentIdAndFileNames {
|
||||
final String mContentId;
|
||||
final List<String> mFileNameList = new ArrayList();
|
||||
final Map<String, List<String>> mLibraryToFileNameMap = new TreeMap();
|
||||
|
||||
ContentIdAndFileNames(String contentId) {
|
||||
mContentId = contentId;
|
||||
@ -120,7 +129,7 @@ class LicenseHtmlGeneratorFromXml {
|
||||
parse(xmlFile);
|
||||
}
|
||||
|
||||
if (mFileNameToContentIdMap.isEmpty() || mContentIdToFileContentMap.isEmpty()) {
|
||||
if (mFileNameToLibraryToContentIdMap.isEmpty() || mContentIdToFileContentMap.isEmpty()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -128,7 +137,7 @@ class LicenseHtmlGeneratorFromXml {
|
||||
try {
|
||||
writer = new PrintWriter(outputFile);
|
||||
|
||||
generateHtml(mFileNameToContentIdMap, mContentIdToFileContentMap, writer,
|
||||
generateHtml(mFileNameToLibraryToContentIdMap, mContentIdToFileContentMap, writer,
|
||||
noticeHeader);
|
||||
|
||||
writer.flush();
|
||||
@ -157,7 +166,7 @@ class LicenseHtmlGeneratorFromXml {
|
||||
in = new FileReader(xmlFile);
|
||||
}
|
||||
|
||||
parse(in, mFileNameToContentIdMap, mContentIdToFileContentMap);
|
||||
parse(in, mFileNameToLibraryToContentIdMap, mContentIdToFileContentMap);
|
||||
|
||||
in.close();
|
||||
} catch (XmlPullParserException | IOException e) {
|
||||
@ -180,7 +189,8 @@ class LicenseHtmlGeneratorFromXml {
|
||||
*
|
||||
* <licenses>
|
||||
* <file-name contentId="content_id_of_license1">file1</file-name>
|
||||
* <file-name contentId="content_id_of_license2">file2</file-name>
|
||||
* <file-name contentId="content_id_of_license2" lib="name of library">file2</file-name>
|
||||
* <file-name contentId="content_id_of_license2" lib="another library">file2</file-name>
|
||||
* ...
|
||||
* <file-content contentId="content_id_of_license1">license1 file contents</file-content>
|
||||
* <file-content contentId="content_id_of_license2">license2 file contents</file-content>
|
||||
@ -188,10 +198,12 @@ class LicenseHtmlGeneratorFromXml {
|
||||
* </licenses>
|
||||
*/
|
||||
@VisibleForTesting
|
||||
static void parse(InputStreamReader in, Map<String, Set<String>> outFileNameToContentIdMap,
|
||||
static void parse(InputStreamReader in,
|
||||
Map<String, Map<String, Set<String>>> outFileNameToLibraryToContentIdMap,
|
||||
Map<String, String> outContentIdToFileContentMap)
|
||||
throws XmlPullParserException, IOException {
|
||||
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<String, Set<String>>();
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap =
|
||||
new HashMap<String, Map<String, Set<String>>>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<String, String>();
|
||||
|
||||
XmlPullParser parser = Xml.newPullParser();
|
||||
@ -205,12 +217,15 @@ class LicenseHtmlGeneratorFromXml {
|
||||
if (state == XmlPullParser.START_TAG) {
|
||||
if (TAG_FILE_NAME.equals(parser.getName())) {
|
||||
String contentId = parser.getAttributeValue("", ATTR_CONTENT_ID);
|
||||
String libraryName = parser.getAttributeValue("", ATTR_LIBRARY_NAME);
|
||||
if (!TextUtils.isEmpty(contentId)) {
|
||||
String fileName = readText(parser).trim();
|
||||
if (!TextUtils.isEmpty(fileName)) {
|
||||
Set<String> contentIds =
|
||||
fileNameToContentIdMap.computeIfAbsent(
|
||||
fileName, k -> new HashSet<>());
|
||||
Map<String, Set<String>> libs =
|
||||
fileNameToLibraryToContentIdMap.computeIfAbsent(
|
||||
fileName, k -> new HashMap<>());
|
||||
Set<String> contentIds = libs.computeIfAbsent(
|
||||
libraryName, k -> new HashSet<>());
|
||||
contentIds.add(contentId);
|
||||
}
|
||||
}
|
||||
@ -229,11 +244,17 @@ class LicenseHtmlGeneratorFromXml {
|
||||
|
||||
state = parser.next();
|
||||
}
|
||||
for (Map.Entry<String, Set<String>> entry : fileNameToContentIdMap.entrySet()) {
|
||||
outFileNameToContentIdMap.merge(
|
||||
entry.getKey(), entry.getValue(), (s1, s2) -> {
|
||||
s1.addAll(s2);
|
||||
return s1;
|
||||
for (Map.Entry<String, Map<String, Set<String>>> mapEntry :
|
||||
fileNameToLibraryToContentIdMap.entrySet()) {
|
||||
outFileNameToLibraryToContentIdMap.merge(
|
||||
mapEntry.getKey(), mapEntry.getValue(), (m1, m2) -> {
|
||||
for (Map.Entry<String, Set<String>> entry : m2.entrySet()) {
|
||||
m1.merge(entry.getKey(), entry.getValue(), (s1, s2) -> {
|
||||
s1.addAll(s2);
|
||||
return s1;
|
||||
});
|
||||
}
|
||||
return m1;
|
||||
});
|
||||
}
|
||||
outContentIdToFileContentMap.putAll(contentIdToFileContentMap);
|
||||
@ -251,13 +272,28 @@ class LicenseHtmlGeneratorFromXml {
|
||||
}
|
||||
|
||||
@VisibleForTesting
|
||||
static void generateHtml(Map<String, Set<String>> fileNameToContentIdMap,
|
||||
static void generateHtml(Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap,
|
||||
Map<String, String> contentIdToFileContentMap, PrintWriter writer,
|
||||
String noticeHeader) {
|
||||
List<String> fileNameList = new ArrayList();
|
||||
fileNameList.addAll(fileNameToContentIdMap.keySet());
|
||||
fileNameList.addAll(fileNameToLibraryToContentIdMap.keySet());
|
||||
Collections.sort(fileNameList);
|
||||
|
||||
SortedMap<String, Set<String>> libraryToContentIdMap = new TreeMap();
|
||||
for (Map<String, Set<String>> libraryToContentValue :
|
||||
fileNameToLibraryToContentIdMap.values()) {
|
||||
for (Map.Entry<String, Set<String>> entry : libraryToContentValue.entrySet()) {
|
||||
if (TextUtils.isEmpty(entry.getKey())) {
|
||||
continue;
|
||||
}
|
||||
libraryToContentIdMap.merge(
|
||||
entry.getKey(), entry.getValue(), (s1, s2) -> {
|
||||
s1.addAll(s2);
|
||||
return s1;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
writer.println(HTML_HEAD_STRING);
|
||||
|
||||
if (!TextUtils.isEmpty(noticeHeader)) {
|
||||
@ -268,21 +304,56 @@ class LicenseHtmlGeneratorFromXml {
|
||||
Map<String, Integer> contentIdToOrderMap = new HashMap();
|
||||
List<ContentIdAndFileNames> contentIdAndFileNamesList = new ArrayList();
|
||||
|
||||
if (!libraryToContentIdMap.isEmpty()) {
|
||||
writer.println(LIBRARY_HEAD_STRING);
|
||||
for (Map.Entry<String, Set<String>> entry: libraryToContentIdMap.entrySet()) {
|
||||
String libraryName = entry.getKey();
|
||||
for (String contentId : entry.getValue()) {
|
||||
// Assigns an id to a newly referred license file content.
|
||||
if (!contentIdToOrderMap.containsKey(contentId)) {
|
||||
contentIdToOrderMap.put(contentId, count);
|
||||
|
||||
// An index in contentIdAndFileNamesList is the order of each element.
|
||||
contentIdAndFileNamesList.add(new ContentIdAndFileNames(contentId));
|
||||
count++;
|
||||
}
|
||||
int id = contentIdToOrderMap.get(contentId);
|
||||
writer.format("<li><a href=\"#id%d\">%s</a></li>\n", id, libraryName);
|
||||
}
|
||||
}
|
||||
writer.println(LIBRARY_TAIL_STRING);
|
||||
}
|
||||
|
||||
// Prints all the file list with a link to its license file content.
|
||||
for (String fileName : fileNameList) {
|
||||
for (String contentId : fileNameToContentIdMap.get(fileName)) {
|
||||
// Assigns an id to a newly referred license file content.
|
||||
if (!contentIdToOrderMap.containsKey(contentId)) {
|
||||
contentIdToOrderMap.put(contentId, count);
|
||||
|
||||
// An index in contentIdAndFileNamesList is the order of each element.
|
||||
contentIdAndFileNamesList.add(new ContentIdAndFileNames(contentId));
|
||||
count++;
|
||||
for (Map.Entry<String, Set<String>> libToContentId :
|
||||
fileNameToLibraryToContentIdMap.get(fileName).entrySet()) {
|
||||
String libraryName = libToContentId.getKey();
|
||||
if (libraryName == null) {
|
||||
libraryName = "";
|
||||
}
|
||||
for (String contentId : libToContentId.getValue()) {
|
||||
// Assigns an id to a newly referred license file content.
|
||||
if (!contentIdToOrderMap.containsKey(contentId)) {
|
||||
contentIdToOrderMap.put(contentId, count);
|
||||
|
||||
int id = contentIdToOrderMap.get(contentId);
|
||||
contentIdAndFileNamesList.get(id).mFileNameList.add(fileName);
|
||||
writer.format("<li><a href=\"#id%d\">%s</a></li>\n", id, fileName);
|
||||
// An index in contentIdAndFileNamesList is the order of each element.
|
||||
contentIdAndFileNamesList.add(new ContentIdAndFileNames(contentId));
|
||||
count++;
|
||||
}
|
||||
|
||||
int id = contentIdToOrderMap.get(contentId);
|
||||
ContentIdAndFileNames elem = contentIdAndFileNamesList.get(id);
|
||||
List<String> files = elem.mLibraryToFileNameMap.computeIfAbsent(
|
||||
libraryName, k -> new ArrayList());
|
||||
files.add(fileName);
|
||||
if (TextUtils.isEmpty(libraryName)) {
|
||||
writer.format("<li><a href=\"#id%d\">%s</a></li>\n", id, fileName);
|
||||
} else {
|
||||
writer.format("<li><a href=\"#id%d\">%s - %s</a></li>\n",
|
||||
id, fileName, libraryName);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -292,19 +363,27 @@ class LicenseHtmlGeneratorFromXml {
|
||||
// Prints all contents of the license files in order of id.
|
||||
for (ContentIdAndFileNames contentIdAndFileNames : contentIdAndFileNamesList) {
|
||||
writer.format("<tr id=\"id%d\"><td class=\"same-license\">\n", count);
|
||||
writer.println("<div class=\"label\">Notices for file(s):</div>");
|
||||
writer.println("<div class=\"file-list\">");
|
||||
for (String fileName : contentIdAndFileNames.mFileNameList) {
|
||||
writer.format("%s <br/>\n", fileName);
|
||||
for (Map.Entry<String, List<String>> libraryFiles :
|
||||
contentIdAndFileNames.mLibraryToFileNameMap.entrySet()) {
|
||||
String libraryName = libraryFiles.getKey();
|
||||
if (TextUtils.isEmpty(libraryName)) {
|
||||
writer.println("<div class=\"label\">Notices for file(s):</div>");
|
||||
} else {
|
||||
writer.format("<div class=\"label\"><strong>%s</strong> used by:</div>\n",
|
||||
libraryName);
|
||||
}
|
||||
writer.println("<div class=\"file-list\">");
|
||||
for (String fileName : libraryFiles.getValue()) {
|
||||
writer.format("%s <br/>\n", fileName);
|
||||
}
|
||||
writer.println("</div><!-- file-list -->");
|
||||
count++;
|
||||
}
|
||||
writer.println("</div><!-- file-list -->");
|
||||
writer.println("<pre class=\"license-text\">");
|
||||
writer.println(contentIdToFileContentMap.get(
|
||||
contentIdAndFileNames.mContentId));
|
||||
writer.println("</pre><!-- license-text -->");
|
||||
writer.println("</td></tr><!-- same-license -->");
|
||||
|
||||
count++;
|
||||
}
|
||||
|
||||
writer.println(HTML_REAR_STRING);
|
||||
|
@ -36,7 +36,7 @@ import java.util.Set;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class LicenseHtmlGeneratorFromXmlTest {
|
||||
private static final String VALILD_XML_STRING =
|
||||
private static final String VALID_OLD_XML_STRING =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
+ "<licenses>\n"
|
||||
+ "<file-name contentId=\"0\">/file0</file-name>\n"
|
||||
@ -44,7 +44,15 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
||||
+ "<file-content contentId=\"0\"><![CDATA[license content #0]]></file-content>\n"
|
||||
+ "</licenses>";
|
||||
|
||||
private static final String INVALILD_XML_STRING =
|
||||
private static final String VALID_NEW_XML_STRING =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
+ "<licenses>\n"
|
||||
+ "<file-name contentId=\"0\" lib=\"libA\">/file0</file-name>\n"
|
||||
+ "<file-name contentId=\"0\" lib=\"libB\">/file1</file-name>\n"
|
||||
+ "<file-content contentId=\"0\"><![CDATA[license content #0]]></file-content>\n"
|
||||
+ "</licenses>";
|
||||
|
||||
private static final String INVALID_XML_STRING =
|
||||
"<?xml version=\"1.0\" encoding=\"utf-8\"?>\n"
|
||||
+ "<licenses2>\n"
|
||||
+ "<file-name contentId=\"0\">/file0</file-name>\n"
|
||||
@ -64,13 +72,13 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
||||
+ "</style>\n"
|
||||
+ "</head>"
|
||||
+ "<body topmargin=\"0\" leftmargin=\"0\" rightmargin=\"0\" bottommargin=\"0\">\n"
|
||||
+ "<div class=\"toc\">\n"
|
||||
+ "<ul>\n";
|
||||
+ "<div class=\"toc\">\n";
|
||||
|
||||
private static final String HTML_CUSTOM_HEADING = "Custom heading";
|
||||
|
||||
private static final String HTML_BODY_STRING =
|
||||
"<li><a href=\"#id0\">/file0</a></li>\n"
|
||||
private static final String HTML_OLD_BODY_STRING =
|
||||
"<ul class=\"files\">\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"
|
||||
+ "</ul>\n"
|
||||
@ -97,66 +105,181 @@ public class LicenseHtmlGeneratorFromXmlTest {
|
||||
+ "</td></tr><!-- same-license -->\n"
|
||||
+ "</table></body></html>\n";
|
||||
|
||||
private static final String EXPECTED_HTML_STRING = HTML_HEAD_STRING + HTML_BODY_STRING;
|
||||
private static final String HTML_NEW_BODY_STRING =
|
||||
"<strong>Libraries</strong>\n"
|
||||
+ "<ul class=\"libraries\">\n"
|
||||
+ "<li><a href=\"#id0\">libA</a></li>\n"
|
||||
+ "<li><a href=\"#id1\">libB</a></li>\n"
|
||||
+ "</ul>\n"
|
||||
+ "<strong>Files</strong>\n"
|
||||
+ "<ul class=\"files\">\n"
|
||||
+ "<li><a href=\"#id0\">/file0 - libA</a></li>\n"
|
||||
+ "<li><a href=\"#id1\">/file0 - libB</a></li>\n"
|
||||
+ "<li><a href=\"#id0\">/file1 - libA</a></li>\n"
|
||||
+ "</ul>\n"
|
||||
+ "</div><!-- table of contents -->\n"
|
||||
+ "<table cellpadding=\"0\" cellspacing=\"0\" border=\"0\">\n"
|
||||
+ "<tr id=\"id0\"><td class=\"same-license\">\n"
|
||||
+ "<div class=\"label\">Notices for file(s):</div>\n"
|
||||
+ "<div class=\"file-list\">\n"
|
||||
+ "/file0 <br/>\n"
|
||||
+ "/file1 <br/>\n"
|
||||
+ "</div><!-- file-list -->\n"
|
||||
+ "<pre class=\"license-text\">\n"
|
||||
+ "license content #0\n"
|
||||
+ "</pre><!-- license-text -->\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";
|
||||
|
||||
private static final String EXPECTED_HTML_STRING_WITH_CUSTOM_HEADING =
|
||||
HTML_HEAD_STRING + HTML_CUSTOM_HEADING + "\n" + HTML_BODY_STRING;
|
||||
private static final String EXPECTED_OLD_HTML_STRING = HTML_HEAD_STRING + HTML_OLD_BODY_STRING;
|
||||
|
||||
private static final String EXPECTED_NEW_HTML_STRING = HTML_HEAD_STRING + HTML_NEW_BODY_STRING;
|
||||
|
||||
private static final String EXPECTED_OLD_HTML_STRING_WITH_CUSTOM_HEADING =
|
||||
HTML_HEAD_STRING + HTML_CUSTOM_HEADING + "\n" + HTML_OLD_BODY_STRING;
|
||||
|
||||
private static final String EXPECTED_NEW_HTML_STRING_WITH_CUSTOM_HEADING =
|
||||
HTML_HEAD_STRING + HTML_CUSTOM_HEADING + "\n" + HTML_NEW_BODY_STRING;
|
||||
|
||||
@Test
|
||||
public void testParseValidXmlStream() throws XmlPullParserException, IOException {
|
||||
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
|
||||
LicenseHtmlGeneratorFromXml.parse(
|
||||
new InputStreamReader(new ByteArrayInputStream(VALILD_XML_STRING.getBytes())),
|
||||
fileNameToContentIdMap, contentIdToFileContentMap);
|
||||
assertThat(fileNameToContentIdMap.size()).isEqualTo(2);
|
||||
assertThat(fileNameToContentIdMap.get("/file0")).containsExactly("0");
|
||||
assertThat(fileNameToContentIdMap.get("/file1")).containsExactly("0");
|
||||
new InputStreamReader(new ByteArrayInputStream(VALID_OLD_XML_STRING.getBytes())),
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap);
|
||||
assertThat(fileNameToLibraryToContentIdMap.size()).isEqualTo(1);
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("").size()).isEqualTo(2);
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("").get("/file0")).containsExactly("0");
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("").get("/file1")).containsExactly("0");
|
||||
assertThat(contentIdToFileContentMap.size()).isEqualTo(1);
|
||||
assertThat(contentIdToFileContentMap.get("0")).isEqualTo("license content #0");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParseNewValidXmlStream() throws XmlPullParserException, IOException {
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
|
||||
LicenseHtmlGeneratorFromXml.parse(
|
||||
new InputStreamReader(new ByteArrayInputStream(VALID_NEW_XML_STRING.getBytes())),
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap);
|
||||
assertThat(fileNameToLibraryToContentIdMap.size()).isEqualTo(2);
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("libA").size()).isEqualTo(1);
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("libB").size()).isEqualTo(1);
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("libA").get("/file0")).containsExactly("0");
|
||||
assertThat(fileNameToLibraryToContentIdMap.get("libB").get("/file1")).containsExactly("0");
|
||||
assertThat(contentIdToFileContentMap.size()).isEqualTo(1);
|
||||
assertThat(contentIdToFileContentMap.get("0")).isEqualTo("license content #0");
|
||||
}
|
||||
|
||||
@Test(expected = XmlPullParserException.class)
|
||||
public void testParseInvalidXmlStream() throws XmlPullParserException, IOException {
|
||||
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
|
||||
LicenseHtmlGeneratorFromXml.parse(
|
||||
new InputStreamReader(new ByteArrayInputStream(INVALILD_XML_STRING.getBytes())),
|
||||
fileNameToContentIdMap, contentIdToFileContentMap);
|
||||
new InputStreamReader(new ByteArrayInputStream(INVALID_XML_STRING.getBytes())),
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateHtml() {
|
||||
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||
Map<String, Set<String>> toOne = new HashMap<>();
|
||||
|
||||
fileNameToContentIdMap.put("/file0", new HashSet<String>(Arrays.asList("0", "1")));
|
||||
fileNameToContentIdMap.put("/file1", new HashSet<String>(Arrays.asList("0")));
|
||||
toBoth.put("", new HashSet<String>(Arrays.asList("0", "1")));
|
||||
toOne.put("", new HashSet<String>(Arrays.asList("0")));
|
||||
|
||||
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
|
||||
fileNameToLibraryToContentIdMap.put("/file1", toOne);
|
||||
contentIdToFileContentMap.put("0", "license content #0");
|
||||
contentIdToFileContentMap.put("1", "license content #1");
|
||||
|
||||
StringWriter output = new StringWriter();
|
||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||
fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output), "");
|
||||
assertThat(output.toString()).isEqualTo(EXPECTED_HTML_STRING);
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||
new PrintWriter(output), "");
|
||||
assertThat(output.toString()).isEqualTo(EXPECTED_OLD_HTML_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateNewHtml() {
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||
Map<String, Set<String>> toOne = new HashMap<>();
|
||||
|
||||
toBoth.put("libA", new HashSet<String>(Arrays.asList("0")));
|
||||
toBoth.put("libB", new HashSet<String>(Arrays.asList("1")));
|
||||
toOne.put("libA", new HashSet<String>(Arrays.asList("0")));
|
||||
|
||||
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
|
||||
fileNameToLibraryToContentIdMap.put("/file1", toOne);
|
||||
contentIdToFileContentMap.put("0", "license content #0");
|
||||
contentIdToFileContentMap.put("1", "license content #1");
|
||||
|
||||
StringWriter output = new StringWriter();
|
||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||
new PrintWriter(output), "");
|
||||
assertThat(output.toString()).isEqualTo(EXPECTED_NEW_HTML_STRING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateHtmlWithCustomHeading() {
|
||||
Map<String, Set<String>> fileNameToContentIdMap = new HashMap<>();
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||
Map<String, Set<String>> toOne = new HashMap<>();
|
||||
|
||||
fileNameToContentIdMap.put("/file0", new HashSet<String>(Arrays.asList("0", "1")));
|
||||
fileNameToContentIdMap.put("/file1", new HashSet<String>(Arrays.asList("0")));
|
||||
toBoth.put("", new HashSet<String>(Arrays.asList("0", "1")));
|
||||
toOne.put("", new HashSet<String>(Arrays.asList("0")));
|
||||
|
||||
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
|
||||
fileNameToLibraryToContentIdMap.put("/file1", toOne);
|
||||
contentIdToFileContentMap.put("0", "license content #0");
|
||||
contentIdToFileContentMap.put("1", "license content #1");
|
||||
|
||||
StringWriter output = new StringWriter();
|
||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||
fileNameToContentIdMap, contentIdToFileContentMap, new PrintWriter(output),
|
||||
HTML_CUSTOM_HEADING);
|
||||
assertThat(output.toString()).isEqualTo(EXPECTED_HTML_STRING_WITH_CUSTOM_HEADING);
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||
new PrintWriter(output), HTML_CUSTOM_HEADING);
|
||||
assertThat(output.toString()).isEqualTo(EXPECTED_OLD_HTML_STRING_WITH_CUSTOM_HEADING);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGenerateNewHtmlWithCustomHeading() {
|
||||
Map<String, Map<String, Set<String>>> fileNameToLibraryToContentIdMap = new HashMap<>();
|
||||
Map<String, String> contentIdToFileContentMap = new HashMap<>();
|
||||
Map<String, Set<String>> toBoth = new HashMap<>();
|
||||
Map<String, Set<String>> toOne = new HashMap<>();
|
||||
|
||||
toBoth.put("libA", new HashSet<String>(Arrays.asList("0")));
|
||||
toBoth.put("libB", new HashSet<String>(Arrays.asList("1")));
|
||||
toOne.put("libA", new HashSet<String>(Arrays.asList("0")));
|
||||
|
||||
fileNameToLibraryToContentIdMap.put("/file0", toBoth);
|
||||
fileNameToLibraryToContentIdMap.put("/file1", toOne);
|
||||
contentIdToFileContentMap.put("0", "license content #0");
|
||||
contentIdToFileContentMap.put("1", "license content #1");
|
||||
|
||||
StringWriter output = new StringWriter();
|
||||
LicenseHtmlGeneratorFromXml.generateHtml(
|
||||
fileNameToLibraryToContentIdMap, contentIdToFileContentMap,
|
||||
new PrintWriter(output), HTML_CUSTOM_HEADING);
|
||||
assertThat(output.toString()).isEqualTo(EXPECTED_NEW_HTML_STRING_WITH_CUSTOM_HEADING);
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user