Search in sources :

Example 1 with CovManager

use of org.eclipse.linuxtools.internal.gcov.parser.CovManager in project linuxtools by eclipse.

the class CovView method displayCovDetailedResult.

public static void displayCovDetailedResult(String binaryPath, String gcda) {
    try {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IFile binary = root.getFileForLocation(new Path(binaryPath));
        IProject project = null;
        if (binary != null) {
            project = binary.getProject();
        }
        // parse and process coverage data
        CovManager cvrgeMnger = new CovManager(binaryPath, project);
        List<String> gcdaPaths = new LinkedList<>();
        gcdaPaths.add(gcda);
        cvrgeMnger.processCovFiles(gcdaPaths, gcda);
        // generate model for view
        cvrgeMnger.fillGcovView();
        for (SourceFile sf : cvrgeMnger.getSourceMap().values()) {
            OpenSourceFileAction.openAnnotatedSourceFile(project, binary, sf, 0);
        }
    } catch (CoreException | IOException e) {
        reportError(e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) LinkedList(java.util.LinkedList)

Example 2 with CovManager

use of org.eclipse.linuxtools.internal.gcov.parser.CovManager in project linuxtools by eclipse.

the class CovView method displayCovResults.

public static void displayCovResults(String binaryPath, String gcda) {
    try {
        IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
        IFile binary = root.getFileForLocation(new Path(binaryPath));
        IProject project = null;
        if (binary != null) {
            project = binary.getProject();
        }
        // parse and process coverage data
        CovManager cvrgeMnger = new CovManager(binaryPath, project);
        List<String> gcdaPaths = cvrgeMnger.getGCDALocations();
        cvrgeMnger.processCovFiles(gcdaPaths, gcda);
        // generate model for view
        cvrgeMnger.fillGcovView();
        // load an Eclipse view
        Date date = new Date(0);
        Date dateCandidate;
        for (String file : gcdaPaths) {
            dateCandidate = new Date(new File(file).lastModified());
            if (dateCandidate.after(date)) {
                date = dateCandidate;
            }
        }
        String timestamp = DateFormat.getInstance().format(date);
        PlatformUI.getWorkbench().getDisplay().syncExec(() -> {
            try {
                displayCovResults(cvrgeMnger, timestamp);
            } catch (PartInitException e) {
                reportError(e);
            }
        });
    } catch (InterruptedException | IOException | CoreException e) {
        reportError(e);
    }
}
Also used : Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) IOException(java.io.IOException) IProject(org.eclipse.core.resources.IProject) Date(java.util.Date) CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) CoreException(org.eclipse.core.runtime.CoreException) PartInitException(org.eclipse.ui.PartInitException) IFile(org.eclipse.core.resources.IFile) File(java.io.File) SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile)

Example 3 with CovManager

use of org.eclipse.linuxtools.internal.gcov.parser.CovManager in project linuxtools by eclipse.

the class GcovAnnotationModel method findSourceCoverageForElement.

private SourceFile findSourceCoverageForElement(ICElement element) {
    List<SourceFile> sources = new ArrayList<>();
    ICProject cProject = element.getCProject();
    IResource elementResource = element.getResource();
    IPath target = GcovAnnotationModelTracker.getInstance().getBinaryPath(cProject.getProject());
    if (target == null) {
        // We cannot find a target for this element, using it's project.
        // This can be caused by linking in a file to the project which may
        // not have a project or may point to another unseen project if the file originated
        // there.
        IProject[] trackedProjects = GcovAnnotationModelTracker.getInstance().getTrackedProjects();
        for (IProject proj : trackedProjects) {
            // element is linked in.
            try {
                FindLinkedResourceVisitor visitor = new FindLinkedResourceVisitor(element);
                proj.accept(visitor, IResource.DEPTH_INFINITE);
                // If we find a match, make note of the target and the real C project.
                if (visitor.foundElement()) {
                    target = GcovAnnotationModelTracker.getInstance().getBinaryPath(proj);
                    cProject = CoreModel.getDefault().getCModel().getCProject(proj.getName());
                    elementResource = visitor.getResource();
                    break;
                }
            } catch (CoreException e) {
            }
        }
        if (target == null) {
            return null;
        }
    }
    try {
        IBinary[] binaries = cProject.getBinaryContainer().getBinaries();
        for (IBinary b : binaries) {
            if (b.getResource().getLocation().equals(target)) {
                CovManager covManager = new CovManager(b.getResource().getLocation().toOSString());
                covManager.processCovFiles(covManager.getGCDALocations(), null);
                sources.addAll(covManager.getAllSrcs());
            }
        }
    } catch (IOException | CoreException | InterruptedException e) {
    }
    if (elementResource != null) {
        IPath elementLocation = elementResource.getLocation();
        if (elementLocation != null) {
            for (SourceFile sf : sources) {
                IPath sfPath = new Path(sf.getName());
                IFile file = STLink2SourceSupport.getFileForPath(sfPath, cProject.getProject());
                if (file != null && elementLocation.equals(file.getLocation())) {
                    return sf;
                }
                // the sources.  Fixes Bug 447554
                if (!sfPath.isAbsolute()) {
                    sfPath = target.removeLastSegments(1).append(sf.getName());
                    if (elementLocation.equals(sfPath.makeAbsolute()) && sfPath.toFile().exists())
                        return sf;
                }
            }
        }
    }
    URI elementURI = element.getLocationURI();
    if (elementURI != null) {
        IPath binFolder = target.removeLastSegments(1);
        for (SourceFile sf : sources) {
            String sfPath = Paths.get(binFolder.toOSString()).resolve(sf.getName()).normalize().toString();
            if (sfPath.equals(elementURI.getPath())) {
                return sf;
            }
        }
    }
    return null;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IFile(org.eclipse.core.resources.IFile) ICProject(org.eclipse.cdt.core.model.ICProject) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IBinary(org.eclipse.cdt.core.model.IBinary) IOException(java.io.IOException) URI(java.net.URI) IProject(org.eclipse.core.resources.IProject) CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) CoreException(org.eclipse.core.runtime.CoreException) SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile) IResource(org.eclipse.core.resources.IResource)

Example 4 with CovManager

use of org.eclipse.linuxtools.internal.gcov.parser.CovManager in project linuxtools by eclipse.

the class CovView method createExportToCSVAction.

@Override
protected IAction createExportToCSVAction() {
    IAction action = new STExportToCSVAction(this.getSTViewer()) {

        @Override
        public void run() {
            Object o = getSTViewer().getInput();
            if (o instanceof CovManager) {
                getExporter().setFilePath(defaultCSVPath);
            }
            super.run();
        }
    };
    return action;
}
Also used : CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) STExportToCSVAction(org.eclipse.linuxtools.dataviewers.actions.STExportToCSVAction) IAction(org.eclipse.jface.action.IAction)

Example 5 with CovManager

use of org.eclipse.linuxtools.internal.gcov.parser.CovManager in project linuxtools by eclipse.

the class CovViewer method handleOpenEvent.

@Override
protected void handleOpenEvent(OpenEvent event) {
    IStructuredSelection selection = (IStructuredSelection) event.getSelection();
    TreeElement element = (TreeElement) selection.getFirstElement();
    if (element != null) {
        if (element.getParent() != null) {
            // $NON-NLS-1$
            String sourceLoc = "";
            long lineNumber = 0;
            if (element.getClass() == CovFileTreeElement.class) {
                sourceLoc = element.getName();
            } else if (element.getClass() == CovFunctionTreeElement.class) {
                sourceLoc = ((CovFunctionTreeElement) element).getSourceFilePath();
                lineNumber = ((CovFunctionTreeElement) element).getFirstLnNmbr();
            }
            CovManager cvm = (CovManager) this.getInput();
            SourceFile sourceFile = cvm.getSourceFile(sourceLoc);
            if (sourceFile != null) {
                IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
                String binaryLoc = cvm.getBinaryPath();
                IPath binaryPath = new Path(binaryLoc);
                IFile binary = root.getFileForLocation(binaryPath);
                IProject project = null;
                if (binary != null) {
                    project = binary.getProject();
                }
                OpenSourceFileAction.openAnnotatedSourceFile(project, binary, sourceFile, (int) lineNumber);
            }
        }
    }
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) CovFunctionTreeElement(org.eclipse.linuxtools.internal.gcov.model.CovFunctionTreeElement) CovManager(org.eclipse.linuxtools.internal.gcov.parser.CovManager) IFile(org.eclipse.core.resources.IFile) IWorkspaceRoot(org.eclipse.core.resources.IWorkspaceRoot) IPath(org.eclipse.core.runtime.IPath) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile) IProject(org.eclipse.core.resources.IProject) CovFileTreeElement(org.eclipse.linuxtools.internal.gcov.model.CovFileTreeElement) CovFunctionTreeElement(org.eclipse.linuxtools.internal.gcov.model.CovFunctionTreeElement) TreeElement(org.eclipse.linuxtools.internal.gcov.model.TreeElement)

Aggregations

CovManager (org.eclipse.linuxtools.internal.gcov.parser.CovManager)5 IFile (org.eclipse.core.resources.IFile)4 IProject (org.eclipse.core.resources.IProject)4 Path (org.eclipse.core.runtime.Path)4 SourceFile (org.eclipse.linuxtools.internal.gcov.parser.SourceFile)4 IOException (java.io.IOException)3 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)3 CoreException (org.eclipse.core.runtime.CoreException)3 IPath (org.eclipse.core.runtime.IPath)2 File (java.io.File)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 LinkedList (java.util.LinkedList)1 IBinary (org.eclipse.cdt.core.model.IBinary)1 ICProject (org.eclipse.cdt.core.model.ICProject)1 IResource (org.eclipse.core.resources.IResource)1 IAction (org.eclipse.jface.action.IAction)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 STExportToCSVAction (org.eclipse.linuxtools.dataviewers.actions.STExportToCSVAction)1