Search in sources :

Example 1 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class CoverEventHandler method addModuleToTree.

// adds module to the statistics tree
private void addModuleToTree(final ModuleStats moduleStats) {
    ICoverageObject root = StatsTreeModel.getInstance().getRoot();
    final IConfiguration config = CoveragePerformer.getPerformer().getConfig();
    final String ppath = ErlangEngine.getInstance().getModelUtilService().getProject(config.getProject()).getWorkspaceProject().getLocation().toString();
    String mpath = config.getModule(moduleStats.getLabel()).getFilePath();
    mpath = mpath.substring(ppath.length());
    log.info(ppath);
    log.info(mpath);
    final String[] parts = mpath.split("/");
    root.setLiniesCount(root.getLinesCount() + moduleStats.getLinesCount());
    root.setCoverCount(root.getCoverCount() + moduleStats.getCoverCount());
    for (int i = 1; i < parts.length - 1; i++) {
        ICoverageObject tmp = root.findChild(parts[i]);
        if (tmp == null) {
            tmp = new StatsTreeObject(ObjectType.FOLDER);
            tmp.setLabel(parts[i]);
        }
        tmp.setLiniesCount(tmp.getLinesCount() + moduleStats.getLinesCount());
        tmp.setCoverCount(tmp.getCoverCount() + moduleStats.getCoverCount());
        root.addChild(parts[i], tmp);
        root = tmp;
    }
    root.addChild(moduleStats.getLabel(), moduleStats);
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) StatsTreeObject(org.erlide.cover.views.model.StatsTreeObject) IConfiguration(org.erlide.cover.api.IConfiguration)

Example 2 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class ExportReports method treeSave.

// saves reports as a tree
private void treeSave(final ICoverageObject obj, final String path, final String lPath) {
    final String pathIn = obj.getHtmlPath();
    final String pathOut = path + File.separator + obj.getLabel() + ".html";
    log.info("pathOut");
    obj.setRelativePath(lPath + File.separator + obj.getLabel() + ".html");
    if (!obj.getType().equals(ObjectType.MODULE)) {
        final String linkPath = "." + File.separator + obj.getLabel();
        final String dirPath = path + File.separator + obj.getLabel();
        final File dir = new File(dirPath);
        dir.mkdir();
        for (final ICoverageObject child : obj.getChildren()) {
            treeSave(child, dirPath, linkPath);
        }
        try {
            final String report = ReportGenerator.getInstance().getHTMLreport(obj, true);
            log.info(report);
            try (final FileWriter writer = new FileWriter(pathOut)) {
                writer.write(report);
            }
            obj.setHtmlPath(pathOut);
        } catch (final IOException e) {
            ErlLogger.error(e);
        }
    } else {
        final File input = new File(pathIn);
        final File output = new File(pathOut);
        try (final FileReader in = new FileReader(input);
            final FileWriter out = new FileWriter(output)) {
            int c;
            while ((c = in.read()) != -1) {
                out.write(c);
            }
        } catch (final IOException e) {
            CoverageHelper.reportError("Could not export HTML reports");
            ErlLogger.error(e);
        }
    }
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) FileWriter(java.io.FileWriter) FileReader(java.io.FileReader) IOException(java.io.IOException) File(java.io.File)

Example 3 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class HtmlReportAction method generateReportTree.

/**
 * Generates html reports
 *
 * @param obj
 * @param path
 */
private void generateReportTree(final ICoverageObject obj, final String path) {
    if (obj.getType().equals(ObjectType.MODULE)) {
        return;
    }
    final String reportPath = path + File.separator + obj.getLabel() + ".html";
    log.info(reportPath);
    final String dirPath = path + File.separator + obj.getLabel();
    final File dir = new File(dirPath);
    dir.mkdir();
    for (final ICoverageObject child : obj.getChildren()) {
        generateReportTree(child, dirPath);
    }
    try {
        final String report = ReportGenerator.getInstance().getHTMLreport(obj, false);
        log.info(report);
        try (final FileWriter writer = new FileWriter(reportPath)) {
            writer.write(report);
        }
        obj.setHtmlPath(reportPath);
    } catch (final IOException e) {
        ErlLogger.error(e);
    }
    for (final ICoverageObject child : obj.getChildren()) {
        generateReportTree(child, dirPath);
    }
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) FileWriter(java.io.FileWriter) IOException(java.io.IOException) File(java.io.File)

Example 4 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class ShowCoverageAction method perform.

@Override
protected void perform(final StatsTreeObject selection) {
    if (selection instanceof ModuleStats) {
        final ModuleStats module = (ModuleStats) selection;
        final String name = module.getLabel() + ".erl";
        if (ifMarkAnnotations(module)) {
            module.couldBeMarked = true;
            marker.addAnnotationsToFile(name);
        }
    } else if (selection instanceof FunctionStats) {
        final FunctionStats fs = (FunctionStats) selection;
        final ModuleStats module = (ModuleStats) fs.getParent();
        final String name = module.getLabel() + ".erl";
        if (ifMarkAnnotations(module)) {
            log.info(fs.getLineStart());
            log.info(fs.getLineEnd());
            module.couldBeMarked = true;
            marker.addAnnotationsFragment(name, fs.getLineStart(), fs.getLineEnd());
        }
    } else if (selection.equals(StatsTreeModel.getInstance().getRoot())) {
        // TODO: check annotation tree, only if root mark all annotations
        final Collection<ICoverageObject> col = selection.getModules();
        for (final ICoverageObject module : col) {
            if (ifMarkAnnotations((ModuleStats) module)) {
                ((ModuleStats) module).couldBeMarked = true;
            } else {
                ((ModuleStats) module).couldBeMarked = false;
            }
        }
        marker.addAnnotations();
    } else {
        final Collection<ICoverageObject> col = selection.getModules();
        for (final ICoverageObject module : col) {
            if (ifMarkAnnotations((ModuleStats) module)) {
                final String name = module.getLabel() + ".erl";
                ((ModuleStats) module).couldBeMarked = true;
                marker.addAnnotationsToFile(name);
            }
        }
    }
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) FunctionStats(org.erlide.cover.views.model.FunctionStats) ModuleStats(org.erlide.cover.views.model.ModuleStats)

Example 5 with ICoverageObject

use of org.erlide.cover.views.model.ICoverageObject in project erlide_eclipse by erlang.

the class StatsViewLabelProvider method getColumnImage.

@Override
public Image getColumnImage(final Object element, final int columnIndex) {
    Image img = null;
    final ICoverageObject statsEl = (ICoverageObject) element;
    switch(columnIndex) {
        case 0:
            final ObjectType type = statsEl.getType();
            switch(type) {
                case FUNCTION:
                    img = Activator.getImageDescriptor(Images.FUNCTION).createImage();
                    break;
                case MODULE:
                    IErlModule m;
                    try {
                        m = ErlangEngine.getInstance().getModel().findModule(statsEl.getLabel());
                    } catch (final ErlModelException e) {
                        ErlLogger.error(e);
                        return null;
                    }
                    img = ErlangElementImageProvider.getErlImageDescriptor(m, ErlangElementImageProvider.SMALL_ICONS).createImage();
                    break;
                case FOLDER:
                    img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(ISharedImages.IMG_OBJ_FOLDER).createImage();
                    break;
                case PROJECT:
                    img = PlatformUI.getWorkbench().getSharedImages().getImageDescriptor(IDE.SharedImages.IMG_OBJ_PROJECT).createImage();
                    break;
                default:
                    break;
            }
            break;
        case 3:
            img = drawPercentage(statsEl.getPercentage());
            break;
        default:
    }
    return img;
}
Also used : ICoverageObject(org.erlide.cover.views.model.ICoverageObject) ObjectType(org.erlide.cover.views.model.ObjectType) ErlModelException(org.erlide.engine.model.ErlModelException) IErlModule(org.erlide.engine.model.root.IErlModule) Image(org.eclipse.swt.graphics.Image)

Aggregations

ICoverageObject (org.erlide.cover.views.model.ICoverageObject)7 File (java.io.File)3 FileWriter (java.io.FileWriter)2 IOException (java.io.IOException)2 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 FileReader (java.io.FileReader)1 ObjectInputStream (java.io.ObjectInputStream)1 IPath (org.eclipse.core.runtime.IPath)1 Image (org.eclipse.swt.graphics.Image)1 ElementListSelectionDialog (org.eclipse.ui.dialogs.ElementListSelectionDialog)1 IConfiguration (org.erlide.cover.api.IConfiguration)1 FunctionStats (org.erlide.cover.views.model.FunctionStats)1 ModuleStats (org.erlide.cover.views.model.ModuleStats)1 ObjectType (org.erlide.cover.views.model.ObjectType)1 StatsTreeObject (org.erlide.cover.views.model.StatsTreeObject)1 ErlModelException (org.erlide.engine.model.ErlModelException)1 IErlModule (org.erlide.engine.model.root.IErlModule)1