diff options
6 files changed, 96 insertions, 40 deletions
diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataFile.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataFile.java index b8852121a0b..f4f0274eccf 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataFile.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataFile.java @@ -11,19 +11,29 @@ package org.eclipse.osee.coverage.vcast; import java.io.File; +import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; +import javax.xml.parsers.ParserConfigurationException; +import org.eclipse.osee.coverage.model.CoverageImport; import org.eclipse.osee.coverage.vcast.CoverageDataUnit.CoverageDataType; -import org.eclipse.osee.framework.core.exception.OseeArgumentException; import org.eclipse.osee.framework.core.exception.OseeCoreException; +import org.eclipse.osee.framework.core.exception.OseeWrappedException; +import org.eclipse.osee.framework.jdk.core.util.AHTML; import org.eclipse.osee.framework.jdk.core.util.Lib; +import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.jdk.core.util.xml.Jaxp; import org.w3c.dom.Document; import org.w3c.dom.Element; +import org.xml.sax.SAXException; /** + * Represents the vcast/<code file>.xml file. Parses the xml within this file and generate + * a CoverageDataUnit for each <coverage_data></coverage_data> block in file. There is ususally + * only one <coverage_data> and one <unit> per .xml file. + * * @author Donald G. Dunne */ public class CoverageDataFile { @@ -32,12 +42,15 @@ public class CoverageDataFile { private static final Pattern lineNumToBranchesPattern = Pattern.compile("\\{([0-9]+);\\s*([0-9]+)\\}"); private final String coverageDataFilename; - public CoverageDataFile(String coverageDataFilename) throws OseeCoreException { + public CoverageDataFile(CoverageImport coverageImport, String coverageDataFilename) throws OseeCoreException { this.coverageDataFilename = coverageDataFilename; File coverageDataFile = getFile(); if (!coverageDataFile.exists()) { - throw new OseeArgumentException("VectorCast coverage data file doesn't exist [%s]", coverageDataFilename); + String errStr = + String.format("VectorCast vcast/<code file>.xml file doesn't exist [%s]", coverageDataFilename); + coverageImport.getLog().logError(AHTML.textToHtml(errStr)); + return; } try { @@ -50,41 +63,60 @@ public class CoverageDataFile { coverageDataUnit.setCoverageType(CoverageDataType.valueOf(unitElement.getAttribute("coverage_type"))); List<Element> subprograms = Jaxp.findElements(unitElement, "subprogram"); + int subprogramNum = 0; for (Element subprogram : subprograms) { + subprogramNum++; String subprogramName = Jaxp.getChildText(subprogram, "name"); - CoverageDataSubProgram coverageDataSubProgram = new CoverageDataSubProgram(subprogramName); - String lineNumbersToBranches = Jaxp.getChildText(subprogram, "line_numbers_to_branches"); - Matcher m = lineNumToBranchesPattern.matcher(lineNumbersToBranches); - while (m.find()) { - // Don't know what to do with >0 branches yet; assume branch coverage (future) - if (!m.group(2).equals("0")) { - System.out.println(String.format("Unhandled branches [%s] for lineNum [%s] subprogram [%s]", - m.group(1), m.group(1), subprogramName)); + if (!Strings.isValid(subprogramName)) { + String errStr = + String.format( + "Subprogram name not found for subprogram number %d in vcast/<code file>.xml for <code file> [%s]. Skipping", + subprogramNum, coverageDataFile); + coverageImport.getLog().logError(AHTML.textToHtml(errStr)); + } else { + CoverageDataSubProgram coverageDataSubProgram = new CoverageDataSubProgram(subprogramName); + String lineNumbersToBranches = Jaxp.getChildText(subprogram, "line_numbers_to_branches"); + Matcher m = lineNumToBranchesPattern.matcher(lineNumbersToBranches); + while (m.find()) { + // Don't know what to do with >0 branches yet; assume branch coverage (future) + if (!m.group(2).equals("0")) { + String errStr = + String.format("Unhandled branches [%s] for lineNum [%s] subprogram [%s]", m.group(1), + m.group(1), subprogramName); + coverageImport.getLog().logError(errStr); + } + coverageDataSubProgram.addLineNumToBranches(new Integer(m.group(1)).intValue(), + new Integer(m.group(2))); } - coverageDataSubProgram.addLineNumToBranches(new Integer(m.group(1)).intValue(), - new Integer(m.group(2))); - } - Element metricsElement = Jaxp.getChild(subprogram, "metrics"); - String complexity = Jaxp.getChildText(metricsElement, "complexity"); - Element coverageElement = Jaxp.getChild(metricsElement, "coverage"); - if (!coverageElement.getAttribute("coverage_type").equals("STATEMENT")) { - System.out.println(String.format("Unhandled coverage_type [%s] for subprogram [%s]. Skipping", - coverageElement.getAttribute("coverage_type"), subprogramName)); - continue; + Element metricsElement = Jaxp.getChild(subprogram, "metrics"); + String complexity = Jaxp.getChildText(metricsElement, "complexity"); + Element coverageElement = Jaxp.getChild(metricsElement, "coverage"); + if (!coverageElement.getAttribute("coverage_type").equals("STATEMENT")) { + String errStr = + String.format("Unhandled coverage_type [%s] for subprogram [%s]. Skipping", + coverageElement.getAttribute("coverage_type"), subprogramName); + coverageImport.getLog().logError(errStr); + continue; + } + String coveredElement = Jaxp.getChildText(coverageElement, "covered"); + String totalElement = Jaxp.getChildText(coverageElement, "total"); + coverageDataSubProgram.setComplexity(new Integer(complexity).intValue()); + coverageDataSubProgram.setCovered(new Integer(coveredElement).intValue()); + coverageDataSubProgram.setTotal(new Integer(totalElement).intValue()); + + coverageDataUnit.addSubProgram(coverageDataSubProgram); } - String coveredElement = Jaxp.getChildText(coverageElement, "covered"); - String totalElement = Jaxp.getChildText(coverageElement, "total"); - coverageDataSubProgram.setComplexity(new Integer(complexity).intValue()); - coverageDataSubProgram.setCovered(new Integer(coveredElement).intValue()); - coverageDataSubProgram.setTotal(new Integer(totalElement).intValue()); - coverageDataUnit.addSubProgram(coverageDataSubProgram); } coverageDataUnits.add(coverageDataUnit); } - } catch (Exception e) { - e.printStackTrace(); + } catch (IOException ex) { + throw new OseeWrappedException(String.format("Exception reading file [%s]", coverageDataFilename), ex); + } catch (SAXException ex) { + throw new OseeWrappedException(String.format("Exception parsing file [%s]", coverageDataFilename), ex); + } catch (ParserConfigurationException ex) { + throw new OseeWrappedException(String.format("Exception parsing file [%s]", coverageDataFilename), ex); } } diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataUnit.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataUnit.java index 921340a3a43..8eb2432cf62 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataUnit.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/CoverageDataUnit.java @@ -14,6 +14,8 @@ import java.util.ArrayList; import java.util.List; /** + * Represents a single <coverage_data></coverage_data> unit as specified in the CoverageDataFile <code file>.xml + * * @author Donald G. Dunne */ public class CoverageDataUnit { diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VCastVcp.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VCastVcp.java index b960c3edb80..a2821dabd86 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VCastVcp.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VCastVcp.java @@ -20,6 +20,9 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.jdk.core.util.Lib; /** + * Represents the <dir>.wrk/vcast.vcp file which lists all the source files and results files specified in this + * directory. + * * @author Donald G. Dunne */ public class VCastVcp { diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpResultsFile.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpResultsFile.java index 88c729deb0c..20edaf3d3cc 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpResultsFile.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpResultsFile.java @@ -21,6 +21,8 @@ import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.logging.OseeLog; /** + * Represents a single RESULTS block found in the <dir>.wrk/vcast.vcp file. + * * @author Donald G. Dunne */ public class VcpResultsFile { diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpSourceFile.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpSourceFile.java index 6b19650f388..35107d2080e 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpSourceFile.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VcpSourceFile.java @@ -17,10 +17,13 @@ import java.util.logging.Level; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.eclipse.osee.coverage.internal.Activator; +import org.eclipse.osee.coverage.model.CoverageImport; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.logging.OseeLog; /** + * Represents a single SOURCE block found in the <dir>.wrk/vcast.vcp file. + * * @author Donald G. Dunne */ public class VcpSourceFile { @@ -77,11 +80,12 @@ public class VcpSourceFile { return vcpSourceLisFile; } - public CoverageDataFile getCoverageDataFile() throws OseeCoreException { + public CoverageDataFile getCoverageDataFile(CoverageImport coverageImport) throws OseeCoreException { if (coverageDataFile == null) { coverageDataFile = - new CoverageDataFile(vcastDirectory + "/vcast/" + getValue(SourceValue.SOURCE_FILENAME).replaceAll( - "\\.(ada|adb|c)$", "\\.xml")); + new CoverageDataFile(coverageImport, + vcastDirectory + "/vcast/" + getValue(SourceValue.SOURCE_FILENAME).replaceAll("\\.(ada|adb|c)$", + "\\.xml")); } return coverageDataFile; } diff --git a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java index df6fcf75fcc..c902f7363ab 100644 --- a/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java +++ b/plugins/org.eclipse.osee.coverage/src/org/eclipse/osee/coverage/vcast/VectorCastAdaCoverageImporter.java @@ -32,6 +32,7 @@ import org.eclipse.osee.coverage.vcast.VcpResultsFile.ResultsValue; import org.eclipse.osee.coverage.vcast.VcpSourceFile.SourceValue; import org.eclipse.osee.framework.core.exception.OseeCoreException; import org.eclipse.osee.framework.jdk.core.type.Pair; +import org.eclipse.osee.framework.jdk.core.util.AHTML; import org.eclipse.osee.framework.jdk.core.util.Lib; import org.eclipse.osee.framework.jdk.core.util.Strings; import org.eclipse.osee.framework.jdk.core.util.io.MatchFilter; @@ -107,6 +108,8 @@ public class VectorCastAdaCoverageImporter implements ICoverageImporter { progressMonitor.beginTask("Importing Source File Data", vcpSourceFiles.size()); } int x = 1; + // Loop through all the source blocks found in <dir>.wrk/vcast.vcp file and create + // CoverageDataFile for each item for (VcpSourceFile vcpSourceFile : vCastVcp.sourceFiles) { String str = String.format("Processing VcpSourceFile %d/%d [%s]...", x++, vcpSourceFiles.size(), vcpSourceFile); @@ -118,19 +121,25 @@ public class VectorCastAdaCoverageImporter implements ICoverageImporter { try { CoverageDataFile coverageDataFile = null; try { - coverageDataFile = vcpSourceFile.getCoverageDataFile(); + coverageDataFile = vcpSourceFile.getCoverageDataFile(coverageImport); } catch (Exception ex) { - coverageImport.getLog().logError( - String.format("Can't find .xml file for source file [%s] exception [%s]", - vcpSourceFile.getValue(SourceValue.SOURCE_FILENAME), ex)); + String errorStr = + String.format( + "Can't process vcast/<code file>.xml file for source file [%s] exception [%s] (see Error Log)", + vcpSourceFile.getValue(SourceValue.SOURCE_FILENAME), ex.getLocalizedMessage()); + coverageImport.getLog().logError(AHTML.textToHtml(errorStr)); + OseeLog.log(Activator.class, Level.SEVERE, errorStr, ex); continue; } try { coverageImport.addImportRecordFile(coverageDataFile.getFile()); } catch (Exception ex) { - coverageImport.getLog().logError("Error Adding Import Record File: " + ex.getLocalizedMessage()); + coverageImport.getLog().logError( + "Error Adding Import Record File (see Error Log): " + ex.getLocalizedMessage()); + OseeLog.log(Activator.class, Level.SEVERE, ex); } for (CoverageDataUnit coverageDataUnit : coverageDataFile.getCoverageDataUnits()) { + // Create CoverageUnit object to represent single <code file>.xml CoverageUnit fileCoverageUnit = coverageImport.createCoverageUnit(null, vcpSourceFile.getValue(SourceValue.SOURCE_FILENAME), ""); String fileNamespace = vectorCastCoverageImportProvider.getFileNamespace(coverageDataUnit.getName()); @@ -145,7 +154,9 @@ public class VectorCastAdaCoverageImporter implements ICoverageImporter { try { coverageImport.addImportRecordFile(vcpSourceLisFile.getFile()); } catch (Exception ex) { - coverageImport.getLog().logError("Error Adding Import Record File: " + ex.getLocalizedMessage()); + coverageImport.getLog().logError( + "Error Adding Import Record File (see Error Log): " + ex.getLocalizedMessage()); + OseeLog.log(Activator.class, Level.SEVERE, ex); } fileCoverageUnit.setFileContents(vcpSourceLisFile.getText()); @@ -229,7 +240,8 @@ public class VectorCastAdaCoverageImporter implements ICoverageImporter { CoverageItem coverageItem = coverageUnit.getCoverageItem(methodNum, executeNum); if (coverageItem == null) { coverageImport.getLog().logError( - String.format("Can't retrieve method [%s] from coverageUnit [%s] for test unit [%s]", + String.format( + "Method [%s] doesn't exist for Coverage Unit [%s] found in test unit vcast/results/.dat file [%s]", methodNum, coverageUnit, testUnitName)); } else { coverageItem.setCoverageMethod(CoverageOptionManager.Test_Unit); @@ -259,7 +271,8 @@ public class VectorCastAdaCoverageImporter implements ICoverageImporter { new MatchFilter(".*\\.DAT"), false); if (numVcastVcpDatFiles != filenames.size()) { coverageImport.getLog().logError( - String.format("Vcast.vcp num results files [%d] doesn't match number of vcast/results/*.dat files [%d]", + String.format( + "Number of results files in Vcast.vcp [%d] doesn't match number of vcast/results/*.dat files [%d]", numVcastVcpDatFiles, filenames.size())); } else { coverageImport.getLog().log("Ok"); |