buildframework/helium/sf/java/quality/src/com/nokia/helium/quality/ant/taskdefs/CASummaryTask.java
author wbernard
Fri, 13 Aug 2010 14:59:05 +0300
changeset 628 7c4a911dc066
child 645 b8d81fa19e7d
permissions -rw-r--r--
helium_11.0.0-e00f171ca185
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
628
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     1
/*
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     2
 * Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiary(-ies).
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     3
 * All rights reserved.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     4
 * This component and the accompanying materials are made available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     5
 * under the terms of the License "Eclipse Public License v1.0"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     6
 * which accompanies this distribution, and is available
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     7
 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     8
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
     9
 * Initial Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    10
 * Nokia Corporation - initial contribution.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    11
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    12
 * Contributors:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    13
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    14
 * Description:  
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    15
 *
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    16
 */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    17
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    18
package com.nokia.helium.quality.ant.taskdefs;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    19
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    20
import java.io.BufferedReader;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    21
import java.io.BufferedWriter;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    22
import java.io.FileNotFoundException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    23
import java.io.FileOutputStream;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    24
import java.io.IOException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    25
import java.io.OutputStreamWriter;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    26
import java.io.UnsupportedEncodingException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    27
import java.util.Hashtable;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    28
import java.util.Iterator;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    29
import java.util.SortedSet;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    30
import java.util.TreeSet;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    31
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    32
import org.apache.tools.ant.Project;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    33
import org.apache.tools.ant.Task;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    34
import java.io.FileReader;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    35
import javax.xml.xpath.XPath;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    36
import org.w3c.dom.NodeList;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    37
import org.w3c.dom.Document;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    38
import javax.xml.parsers.DocumentBuilder;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    39
import javax.xml.parsers.DocumentBuilderFactory;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    40
import javax.xml.parsers.ParserConfigurationException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    41
import javax.xml.xpath.XPathFactory;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    42
import javax.xml.xpath.XPathExpression;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    43
import javax.xml.xpath.XPathConstants;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    44
import javax.xml.xpath.XPathExpressionException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    45
import org.xml.sax.SAXException;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    46
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    47
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    48
/**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    49
 * This Task searches the bc_header.xml and bc_library.xml files created by Binary Comparison and 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    50
 * looks for the typeIds and counts them up. It then prints them in order to write the number of each 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    51
 * typeID that was found to the diamonds output file for display by diamonds.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    52
 * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    53
 * <pre>
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    54
 * &lt;hlm:casummarytask   
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    55
 *             header="true"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    56
 *             diamondsHeaderFileName="C:\diamonds_header.xml" 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    57
 *             diamondsFooterFileName="C:\diamonds_footer.xml"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    58
 *             outptuFile="Z:\output\diamonds/ca_summary_header.xml" 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    59
 *             inputFile="Z:\output\logs/headers_report_minibuild_ido_0.0.03_.xml/&gt;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    60
 * </pre>
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    61
 * 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    62
 * @ant.task name="casummarytask" category="Quality"
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    63
 */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    64
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    65
public class CASummaryTask extends Task {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    66
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    67
    /** String used to look for the tag values in the header xml file **/
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    68
    private static String headerExpression = "//issuelist/headerfile/issue/typeid/text()";
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    69
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    70
    /** String used to look for the tag values in the library xml file **/
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    71
    private static String libraryExpression = "//issuelist/library/issue/typeid/text()";
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    72
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    73
    /** The file containing the CA summary data */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    74
    private String inputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    75
    /** Name of file to write the output to */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    76
    private String outputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    77
    /** Whether we are dealng with a header or library */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    78
    private boolean header;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    79
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    80
    /** Each line of the input file is read into this */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    81
    private String line;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    82
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    83
    /** File descriptor for the input file */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    84
    private BufferedReader inputFileReader;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    85
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    86
    /** File handler used to write the summary numbers to the output file **/
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    87
    private BufferedWriter output; // default init = null
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    88
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    89
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    90
     * File name of the default diamonds XML file header part (1st few lines) used so not writing
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    91
     * the XML text here
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    92
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    93
    private String diamondsHeaderFileName;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    94
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    95
     * File name of the default diamonds XML file footer part (last line) used so not writing the
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    96
     * XML text here
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    97
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    98
    private String diamondsFooterFileName;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
    99
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   100
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   101
     * @param outputFile set the output file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   102
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   103
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   104
    public void setoutputFile(String outputFile) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   105
        this.outputFile = outputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   106
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   107
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   108
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   109
     * @return the outputFile the output file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   110
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   111
    public String getoutputFile() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   112
        return outputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   113
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   114
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   115
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   116
     * @return the inputFile
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   117
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   118
    public String getinputFile() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   119
        return inputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   120
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   121
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   122
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   123
     * @param inputFile the name of file to scan and extract data from
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   124
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   125
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   126
    public void setinputFile(String inputFile) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   127
        this.inputFile = inputFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   128
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   129
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   130
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   131
     * @param diamondsFooterFileName set the diamonds footer file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   132
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   133
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   134
    public void setdiamondsFooterFileName(String diamondsFooterFileName) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   135
        this.diamondsFooterFileName = diamondsFooterFileName;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   136
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   137
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   138
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   139
     * @return the diamondsFooterFileName the diamonds footer file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   140
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   141
    public String getdiamondsFooterFileName() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   142
        return diamondsFooterFileName;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   143
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   144
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   145
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   146
     * @param diamondsHeaderFileName set the diamonds header file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   147
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   148
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   149
    public void setdiamondsHeaderFileName(String diamondsHeaderFileName) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   150
        this.diamondsHeaderFileName = diamondsHeaderFileName;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   151
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   152
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   153
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   154
     * @return the diamondsFooterFileName the diamonds footer file name
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   155
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   156
    public String getdiamondsHeaderFileName() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   157
        return diamondsHeaderFileName;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   158
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   159
    
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   160
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   161
     * @param header set whether we are dealing with a headers or libraries
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   162
     * @ant.required
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   163
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   164
    public void setheader(boolean header) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   165
        this.header = header;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   166
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   167
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   168
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   169
     * @return the fileType whether we are dealing with headers or libraries
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   170
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   171
    public boolean getheader() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   172
        return header;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   173
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   174
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   175
    /** the main part of the code - the method that is called */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   176
    public void execute() {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   177
        log("CASummaryTask execute method with input file : " + inputFile, Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   178
        boolean inputFileFound = true;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   179
        BufferedReader diamondsHeaderFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   180
        BufferedReader diamondsFooterFile;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   181
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   182
        log("output File is " + getoutputFile(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   183
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   184
        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   185
            // open the file with the CA results init
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   186
            inputFileReader = new BufferedReader(new FileReader(inputFile));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   187
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   188
        catch (FileNotFoundException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   189
            log("FileNotFoundException while getting the input file.  : " + inputFile + "  "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   190
                + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   191
            inputFileFound = false; // stops an empty output file being created.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   192
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   193
        if (inputFileFound) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   194
            try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   195
                // write the title stuff for the XML diamonds schema
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   196
                output = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(getoutputFile()), "UTF8"));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   197
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   198
            catch (FileNotFoundException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   199
                log("FileNotFoundException while getting the output file.  : " + getoutputFile()
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   200
                    + "   " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   201
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   202
            catch (UnsupportedEncodingException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   203
                // We are Ignoring the errors as no need to fail the build.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   204
                log("UnsupportedEncodingException while creating the output file : "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   205
                    + getoutputFile() + "   " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   206
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   207
            catch (SecurityException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   208
                // We are Ignoring the errors as no need to fail the build.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   209
                log("SecurityException while creating the output file : " + getoutputFile() + "   "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   210
                    + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   211
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   212
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   213
            if (output != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   214
                // managed to open the output file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   215
                try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   216
                    // write the initial XML text to the file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   217
                    String tempLine;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   218
                    diamondsHeaderFile = null;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   219
                    diamondsHeaderFile = new BufferedReader(new FileReader(getdiamondsHeaderFileName()));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   220
                    while ((tempLine = diamondsHeaderFile.readLine()) != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   221
                        output.write(tempLine);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   222
                        output.newLine();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   223
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   224
                    diamondsHeaderFile.close();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   225
                    boolean tempheader = getheader();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   226
                    if (tempheader) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   227
                        output.write("    <quality aspect=\"compatibility-headers\"> \r\n");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   228
                        // process each line
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   229
                        findTextAndOutput(headerExpression); // read input file and write the output
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   230
                    } else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   231
                        output.write("    <quality aspect=\"compatibility-libs\"> \r\n");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   232
                        // process each line
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   233
                        findTextAndOutput(libraryExpression); // read input file and write the output
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   234
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   235
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   236
                    // write the end of file text
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   237
                    output.write("    </quality>");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   238
                    output.newLine();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   239
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   240
                    diamondsFooterFile = null;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   241
                    diamondsFooterFile = new BufferedReader(new FileReader(getdiamondsFooterFileName()));
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   242
                    while ((tempLine = diamondsFooterFile.readLine()) != null) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   243
                        output.write(tempLine);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   244
                        output.newLine();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   245
                    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   246
                    output.close(); // close the output file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   247
                    diamondsFooterFile.close();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   248
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   249
                catch (FileNotFoundException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   250
                    log("FileNotFoundException while getting the diamonds header file : "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   251
                        + getdiamondsHeaderFileName() + "   " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   252
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   253
                catch (IOException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   254
                    // We are Ignoring the errors as no need to fail the build.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   255
                    log("IOException : " + getdiamondsHeaderFileName() + " output file =  "
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   256
                        + getoutputFile() + "  " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   257
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   258
                catch (IllegalArgumentException exc) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   259
                    // We are Ignoring the errors as no need to fail the build.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   260
                    log("IllegalArgumentException : " + getdiamondsHeaderFileName()
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   261
                        + " output file =  " + getoutputFile() + "  " + exc.getMessage(), Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   262
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   263
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   264
            else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   265
                log("Error: no output File available ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   266
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   267
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   268
        else {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   269
            log("Error: no input File available ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   270
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   271
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   272
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   273
    /**
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   274
     * This is the function that performs the actual file searches and writes the number of occurances
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   275
     * of each typeID to the output xml file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   276
     */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   277
    private void findTextAndOutput(String expression) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   278
        String value;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   279
        Integer count;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   280
        /** place to store the number of typeids found */
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   281
        Hashtable<Integer, Integer> typeIds = new Hashtable<Integer, Integer>();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   282
        int tempKey;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   283
        int tempVal;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   284
        
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   285
        try {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   286
            DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   287
            DocumentBuilder builder = docFactory.newDocumentBuilder();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   288
            Document doc = builder.parse(getinputFile());
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   289
    
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   290
            //creating an XPathFactory:
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   291
            XPathFactory factory = XPathFactory.newInstance();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   292
            //using this factory to create an XPath object: 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   293
            XPath xpath = factory.newXPath();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   294
            //XPath object created compiles the XPath expression: 
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   295
            XPathExpression expr = xpath.compile(expression);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   296
    
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   297
            //expression is evaluated with respect to a certain context node which is doc.
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   298
            Object result = expr.evaluate(doc, XPathConstants.NODESET);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   299
            NodeList nodeList = (NodeList) result;
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   300
            for (int i = 0; i < nodeList.getLength(); i++) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   301
                value = nodeList.item(i).getNodeValue();    //get the value as a string from the xml file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   302
                tempKey = Integer.parseInt(value);          //convert it to an integer so they can be sorted
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   303
                if (!typeIds.containsKey(tempKey)) {        //see if the typeID is already present in the hashtable
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   304
                    typeIds.put(tempKey, 0);                //it's not so create it (stops null pointer exceptions)
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   305
                }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   306
                count = typeIds.get(tempKey);               //get the current count of this typeID
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   307
                count++;                                    //inc the count
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   308
                typeIds.put(tempKey, count);                //write it back to the hashtable
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   309
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   310
            
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   311
            //now sort and write to xml file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   312
            SortedSet<Integer> sortedset = new TreeSet<Integer>(typeIds.keySet());
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   313
            Iterator<Integer> sorted = sortedset.iterator();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   314
            while (sorted.hasNext()) {      //go through each one on the file and write to xml output file
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   315
                tempVal = sorted.next();
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   316
                output.write("        <summary message=\"type ID " + tempVal + " occurs \" value=\"" + typeIds.get(tempVal) + "\"/> \r\n");
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   317
            }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   318
        } catch (ParserConfigurationException err) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   319
            log("Error: ParserConfigurationException: trying to parse xml file ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   320
        } catch (SAXException err) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   321
            log("Error: SAXException: trying to parse xml file ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   322
        } catch (XPathExpressionException err) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   323
            log("Error: XPathExpressionException: trying to parse xml file ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   324
        } catch (IOException err) {
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   325
            log("Error: IOException: trying to parse xml file ", Project.MSG_ERR);
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   326
        }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   327
    }
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   328
7c4a911dc066 helium_11.0.0-e00f171ca185
wbernard
parents:
diff changeset
   329
}