public void writeResultsStatus()

in java/src/org/apache/qetest/Reporter.java [1537:1652]


    public void writeResultsStatus(boolean writeFile)
    {
        final String DEFAULT_SUMMARY_NAME = "ResultsSummary.xml";
        Hashtable resultsHash = createResultsStatusHash();
        resultsHash.put("desc", testComment);
        resultsHash.put("testName", testName);
        //@todo the actual path in the property below may not necessarily 
        //  either exist or be the correct location vis-a-vis the file
        //  that we're writing out - but it should be close
        resultsHash.put(OPT_LOGFILE, reporterProps.getProperty(OPT_LOGFILE, DEFAULT_SUMMARY_NAME));
        try
        {
            resultsHash.put("baseref", System.getProperty("user.dir"));
        } 
        catch (Exception e) { /* no-op, ignore */ }

        String elementName = "teststatus";
        String overallResult = resultToString(getCurrentFileResult());
        // Ask each of our loggers to report this
        for (int i = 0; i < numLoggers; i++)
        {
            loggers[i].logElement(CRITICALMSG, elementName, resultsHash, overallResult);
        }

        // Only continue if user asked us to
        if (!writeFile)
            return;

        // Now write an actual file out as a marker for enclosing 
        //  harnesses and build environments

        // Calculate the name relative to any logfile we have
        String logFileBase = null;
        try
        {
            // CanonicalPath gives a better path, especially if 
            //  you mix your path separators up
            logFileBase = (new File(reporterProps.getProperty(OPT_LOGFILE, DEFAULT_SUMMARY_NAME))).getCanonicalPath();
        } 
        catch (IOException ioe)
        {
            logFileBase = (new File(reporterProps.getProperty(OPT_LOGFILE, DEFAULT_SUMMARY_NAME))).getAbsolutePath();
        }
        logFileBase = (new File(logFileBase)).getParent();
		 		 // Either use the testName or an optionally set summary name
		 		 String summaryFileBase = reporterProps.getProperty(OPT_SUMMARYFILE, testName + ".xml");
        final File[] summaryFiles = 
        {
            // Note array is ordered; should be re-designed so this doesn't matter
            // Coordinate PASS name with results.marker in build.xml
            // File name rationale: put Pass/Fail/etc first, so they 
            //  all show up together in dir listing; include 
            //  testName so you know where it came from; make it 
            //  .xml since it is an XML file
            new File(logFileBase, INCP + "-" + summaryFileBase),
            new File(logFileBase, PASS + "-" + summaryFileBase),
            new File(logFileBase, AMBG + "-" + summaryFileBase),
            new File(logFileBase, FAIL + "-" + summaryFileBase),
            new File(logFileBase, ERRR + "-" + summaryFileBase)
        };
        // Clean up any pre-existing files that might be confused 
        //  as markers from this testrun
        for (int i = 0; i < summaryFiles.length; i++)
        {
            if (summaryFiles[i].exists())
                summaryFiles[i].delete();
        }

        File summaryFile = null;
        switch (getCurrentFileResult())
        {
            case INCP_RESULT:
                summaryFile = summaryFiles[0];
                break;
            case PASS_RESULT:
                summaryFile = summaryFiles[1];
                break;
            case AMBG_RESULT:
                summaryFile = summaryFiles[2];
                break;
            case FAIL_RESULT:
                summaryFile = summaryFiles[3];
                break;
            case ERRR_RESULT:
                summaryFile = summaryFiles[4];
                break;
            default:
                // Use error case, this should never happen
                summaryFile = summaryFiles[4];
                break;
        }
		 		 resultsHash.put(OPT_SUMMARYFILE, summaryFile.getPath());
        // Now actually write out the summary file
        try
        {
            PrintWriter printWriter = new PrintWriter(new FileWriter(summaryFile));
            // Fake the output of Logger.logElement mostly; except 
            //  we add an XML header so this is a legal XML doc
            printWriter.println("<?xml version=\"1.0\"?>"); 
            printWriter.println("<" + elementName); 
            for (Enumeration keys = resultsHash.keys();
                    keys.hasMoreElements(); /* no increment portion */ )
            {
                Object key = keys.nextElement();
                printWriter.println(key + "=\"" + resultsHash.get(key) + "\"");
            }
            printWriter.println(">"); 
            printWriter.println(overallResult); 
            printWriter.println("</" + elementName + ">"); 
            printWriter.close();
        }
        catch(Exception e)
        {
            logErrorMsg("writeResultsStatus: Can't write: " + summaryFile);
        }
    }