Add reference url to XML reports

Bug: 25452494
Change-Id: I007490b19f629cb3d8e171aacb9e05940e1fc8aa
diff --git a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
index 2ccbded..ffe55a9 100644
--- a/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
+++ b/common/host-side/tradefed/src/com/android/compatibility/common/tradefed/result/ResultReporter.java
@@ -310,7 +310,7 @@
             try {
                 File resultFile = ResultHandler.writeResults(mBuildHelper.getSuiteName(),
                         mBuildHelper.getSuiteVersion(), mBuildHelper.getSuitePlan(), mResult,
-                        mResultDir, mStartTime, elapsedTime + mStartTime);
+                        mResultDir, mStartTime, elapsedTime + mStartTime, mReferenceUrl);
                 copyDynamicConfigFiles(mBuildHelper.getDynamicConfigFiles(), mResultDir);
                 copyFormattingFiles(mResultDir);
                 zipResults(mResultDir);
diff --git a/common/util/src/com/android/compatibility/common/util/ResultHandler.java b/common/util/src/com/android/compatibility/common/util/ResultHandler.java
index ecd6570..6efefc3 100644
--- a/common/util/src/com/android/compatibility/common/util/ResultHandler.java
+++ b/common/util/src/com/android/compatibility/common/util/ResultHandler.java
@@ -66,6 +66,7 @@
     private static final String OS_VERSION_ATTR = "os_version";
     private static final String PASS_ATTR = "pass";
     private static final String REPORT_VERSION_ATTR = "report_version";
+    private static final String REFERENCE_URL_ATTR = "reference_url";
     private static final String RESULT_ATTR = "result";
     private static final String RESULT_TAG = "Result";
     private static final String SCREENSHOT_TAG = "Screenshot";
@@ -183,13 +184,14 @@
      * @param result
      * @param resultDir
      * @param startTime
+     * @param referenceUrl A nullable string that can contain a URL to a related data
      * @return The result file created.
      * @throws IOException
      * @throws XmlPullParserException
      */
     public static File writeResults(String suiteName, String suiteVersion, String suitePlan,
-            IInvocationResult result, File resultDir, long startTime, long endTime)
-                    throws IOException, XmlPullParserException {
+            IInvocationResult result, File resultDir, long startTime, long endTime,
+                    String referenceUrl) throws IOException, XmlPullParserException {
         int passed = result.countResults(TestStatus.PASS);
         int failed = result.countResults(TestStatus.FAIL);
         int notExecuted = result.countResults(TestStatus.NOT_EXECUTED);
@@ -208,6 +210,9 @@
         serializer.attribute(NS, SUITE_VERSION_ATTR, suiteVersion);
         serializer.attribute(NS, SUITE_PLAN_ATTR, suitePlan);
         serializer.attribute(NS, REPORT_VERSION_ATTR, RESULT_FILE_VERSION);
+        if (referenceUrl != null) {
+            serializer.attribute(NS, REFERENCE_URL_ATTR, referenceUrl);
+        }
 
         // Device Info
         Set<String> devices = result.getDeviceSerials();
diff --git a/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java b/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java
index 9efd415..be3c109 100644
--- a/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java
+++ b/common/util/tests/src/com/android/compatibility/common/util/ResultHandlerTest.java
@@ -68,6 +68,7 @@
             "at four.big.insects.Marley.sing(Marley.java:10)";
     private static final long START_MS = 1431586801000L;
     private static final long END_MS = 1431673199000L;
+    private static final String REFERENCE_URL="http://android.com";
     private static final String JOIN = "%s%s";
     private static final String XML_BASE =
             "<?xml version='1.0' encoding='UTF-8' standalone='no' ?>" +
@@ -75,7 +76,7 @@
             "<Result start=\"%d\" end=\"%d\" suite_name=\"%s\" suite_version=\"%s\" " +
             "suite_plan=\"%s\" report_version=\"%s\" devices=\"%s\" host_name=\"%s\"" +
             "os_name=\"%s\" os_version=\"%s\" os_arch=\"%s\" java_vendor=\"%s\"" +
-            "java_version=\"%s\">\n" +
+            "java_version=\"%s\" reference_url=\"%s\">\n" +
             "%s%s%s" +
             "</Result>";
     private static final String XML_DEVICE_INFO =
@@ -164,7 +165,7 @@
 
         // Serialize to file
         ResultHandler.writeResults(SUITE_NAME, SUITE_VERSION, SUITE_PLAN, result, resultDir,
-                START_MS, END_MS);
+                START_MS, END_MS, REFERENCE_URL);
 
         // Parse the results and assert correctness
         checkResult(ResultHandler.getResults(resultsDir), resultDir);
@@ -203,7 +204,7 @@
             } catch (UnknownHostException ignored) {}
             String output = String.format(XML_BASE, START_MS, END_MS, SUITE_NAME, SUITE_VERSION,
                     SUITE_PLAN, REPORT_VERSION, DEVICES, hostName, OS_NAME, OS_VERSION, OS_ARCH,
-                    JAVA_VENDOR, JAVA_VERSION, deviceInfo, summary, modules);
+                    JAVA_VENDOR, JAVA_VERSION, REFERENCE_URL, deviceInfo, summary, modules);
             writer.write(output);
             writer.flush();