示例#1
0
  @Override
  public String getColumnText(Object element, XViewerColumn xCol, int columnIndex)
      throws OseeCoreException {
    ICoverage coverage = (ICoverage) element;
    if (xCol.equals(CoverageXViewerFactory.Name)) {
      return coverage.getName();
    }
    if (element instanceof MessageCoverageItem) {
      return "";
    }
    if (xCol.equals(CoverageXViewerFactory.Assignees_Col)) {
      if (element instanceof CoverageUnit) {
        return Artifacts.toString(
            "; ", OseeCoverageUnitStore.getAssignees((CoverageUnit) coverage));
      }
      return "";
    }
    if (xCol.equals(CoverageXViewerFactory.Notes_Col)) {
      return coverage.getNotes();
    }
    if (xCol.equals(CoverageXViewerFactory.Coverage_Percent)) {
      return coverage.getCoveragePercentStr();
    }
    if (xCol.equals(CoverageXViewerFactory.Location)) {
      return coverage.getLocation();
    }
    if (xCol.equals(CoverageXViewerFactory.Full_Path)) {
      return CoverageUtil.getFullPath(coverage);
    }
    if (xCol.equals(CoverageXViewerFactory.Namespace)) {
      return coverage.getNamespace();
    }
    if (xCol.equals(CoverageXViewerFactory.Work_Product_Task)) {
      return coverage.getWorkProductTaskStr();
    }
    if (xCol.equals(CoverageXViewerFactory.Guid)) {
      return coverage.getGuid();
    }
    if (xCol.equals(CoverageXViewerFactory.Unit)) {
      String unit = "";
      if (element instanceof CoverageUnit) {
        unit = coverage.getName();
      } else {
        unit = coverage.getParent().getName();
      }

      return unit;
    }
    if (xCol.equals(CoverageXViewerFactory.Lines_Covered)) {
      if (element instanceof CoverageUnit) {
        return String.valueOf(((CoverageUnit) coverage).getCoverageItemsCoveredCount(true));
      }
    }
    if (xCol.equals(CoverageXViewerFactory.Total_Lines)) {
      if (element instanceof CoverageUnit) {
        return String.valueOf(((CoverageUnit) coverage).getCoverageItems(true).size());
      }
    }

    if (coverage instanceof CoverageItem
        || (coverage instanceof MergeItem
            && ((MergeItem) coverage).getImportItem() instanceof CoverageItem)) {
      CoverageItem coverageItem = null;
      if (coverage instanceof CoverageItem) {
        coverageItem = (CoverageItem) coverage;
      } else {
        coverageItem = (CoverageItem) ((MergeItem) coverage).getImportItem();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Rationale)) {
        return coverageItem.getRationale();
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        return coverageItem.getParent().getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Execution_Number)) {
        return coverageItem.getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Line_Number)) {
        return coverageItem.getLineNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Method)) {
        return coverageItem.getCoverageMethod().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        return coverageItem.getCoverageUnit().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Test_Units)) {
        Collection<String> testUnits = coverageItem.getTestUnits();
        if (testUnits == null) {
          return "";
        }
        return Collections.toString(", ", testUnits);
      }
      return "";
    }
    if (coverage instanceof CoverageUnit
        || (coverage instanceof MergeItem
            && ((MergeItem) coverage).getImportItem() instanceof CoverageUnit)) {
      CoverageUnit coverageUnit = null;
      if (coverage instanceof CoverageUnit) {
        coverageUnit = (CoverageUnit) coverage;
      } else if (coverage instanceof MergeItem) {
        coverageUnit = (CoverageUnit) ((MergeItem) coverage).getImportItem();
      }
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        return coverageUnit.getParentCoverageUnit() == null
            ? ""
            : coverageUnit.getParentCoverageUnit().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        return coverageUnit.getOrderNumber();
      }
    }
    if (coverage instanceof CoverageItem) {
      CoverageItem coverageItem = (CoverageItem) coverage;
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        return coverageItem.getParent() == null ? "" : coverageItem.getParent().getName();
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        return coverageItem.getParent() == null ? "" : coverageItem.getParent().getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Execution_Number)) {
        return coverageItem.getOrderNumber();
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Method)) {
        return coverageItem.getCoverageMethod().getName();
      }
    }
    if (coverage instanceof MergeItem
        && (((MergeItem) coverage).getImportItem() instanceof CoverageItem
            || ((MergeItem) coverage).getPackageItem() instanceof CoverageItem)) {
      MergeItem mergeItem = (MergeItem) coverage;
      ICoverage importItem = mergeItem.getImportItem();
      ICoverage packageItem = mergeItem.getPackageItem();
      if (xCol.equals(CoverageXViewerFactory.Parent_Coverage_Unit)) {
        if (importItem != null && importItem.getParent() != null) {
          return importItem.getParent().getName();
        } else if (packageItem != null && packageItem.getParent() != null) {
          return packageItem.getParent().getName();
        }
        return "";
      }
      if (xCol.equals(CoverageXViewerFactory.Method_Number)) {
        if (importItem != null && importItem.getParent() != null) {
          return importItem.getParent().getOrderNumber();
        } else if (packageItem != null && packageItem.getParent() != null) {
          return packageItem.getParent().getOrderNumber();
        }
        return "";
      }
      if (xCol.equals(CoverageXViewerFactory.Execution_Number)) {
        if (importItem != null) {
          return importItem.getOrderNumber();
        } else if (packageItem != null) {
          return packageItem.getOrderNumber();
        }
        return "";
      }
      if (xCol.equals(CoverageXViewerFactory.Coverage_Method)) {
        if (importItem != null) {
          return ((CoverageItem) importItem).getCoverageMethod().getName();
        } else if (packageItem != null) {
          return ((CoverageItem) packageItem).getCoverageMethod().getName();
        }
        return "";
      }
    }
    return "";
  }
示例#2
0
 public static CoverageUnit createCodeUnit(
     URL url, ICoverageUnitFileContentsProvider fileContentsProvider) throws OseeCoreException {
   Conditions.checkNotNull(url, "url", "Valid filename must be specified");
   InputStream inputStream = null;
   CoverageUnit fileCoverageUnit = null;
   try {
     inputStream = url.openStream();
     Conditions.checkNotNull(inputStream, "input stream", "File doesn't exist [%s]", url);
     // Store file as CoverageUnit
     File file = new File(url.getFile());
     String filename = file.getCanonicalFile().getName();
     fileCoverageUnit =
         CoverageUnitFactory.createCoverageUnit(
             null, filename, url.getFile(), fileContentsProvider);
     String fileStr = Lib.inputStreamToString(inputStream);
     Matcher m = packagePattern.matcher(fileStr);
     if (m.find()) {
       fileCoverageUnit.setNamespace(m.group(1));
     } else {
       throw new OseeArgumentException("Can't find package for [%s]", url);
     }
     fileCoverageUnit.setFileContents(fileStr);
     CoverageUnit coverageUnit = null;
     int lineNum = 0;
     for (String line : fileStr.split("(\r\n|\n)")) {
       if (line.contains("IGNORE")) {
         continue;
       }
       lineNum++;
       // Determine if method; store as CoverageUnit
       m = methodPattern.matcher(line);
       if (m.find()) {
         String name = m.group(3);
         coverageUnit =
             CoverageUnitFactory.createCoverageUnit(
                 fileCoverageUnit, name, "Line " + lineNum, fileContentsProvider);
         // Note: CoverageUnit's orderNumber is set by executeLine match below
         fileCoverageUnit.addCoverageUnit(coverageUnit);
         // Duplicate this method as error case for importing
         if (filename.contains("AuxPowerUnit2") && name.equals("clear")) {
           CoverageUnit duplicateCoverageUnit =
               CoverageUnitFactory.createCoverageUnit(
                   fileCoverageUnit, name, "Line " + lineNum, fileContentsProvider);
           duplicateCoverageUnit.setOrderNumber("2");
           fileCoverageUnit.addCoverageUnit(duplicateCoverageUnit);
           CoverageItem item =
               new CoverageItem(duplicateCoverageUnit, CoverageOptionManager.Not_Covered, "1");
           item.setName("return super.getColumn(index)");
           duplicateCoverageUnit.addCoverageItem(item);
         }
       }
       // Determine if executable coverage line; store as CoverageItem
       m = executeLine.matcher(line);
       if (m.find()) {
         String lineText = m.group(1);
         String methodNum = m.group(2);
         String executeNum = m.group(3);
         String testUnits = m.group(4);
         boolean covered = !testUnits.equals("n");
         CoverageItem coverageItem =
             new CoverageItem(
                 coverageUnit,
                 covered ? CoverageOptionManager.Test_Unit : CoverageOptionManager.Not_Covered,
                 executeNum);
         coverageUnit.setOrderNumber(methodNum);
         coverageItem.setName(lineText);
         coverageItem.setOrderNumber(executeNum);
         coverageUnit.addCoverageItem(coverageItem);
         if (covered) {
           for (String testUnitName : testUnits.split("\\|")) {
             coverageItem.addTestUnitName(testUnitName);
           }
         }
       }
     }
   } catch (IOException ex) {
     OseeExceptions.wrapAndThrow(ex);
   }
   return fileCoverageUnit;
 }