Search in sources :

Example 1 with SourceFile

use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile 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 SourceFile

use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile 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 3 with SourceFile

use of org.eclipse.linuxtools.internal.gcov.parser.SourceFile 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)

Example 4 with SourceFile

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

the class STAnnotatedSourceNotFoundEditor method openSourceFileAtLocation.

@Override
protected void openSourceFileAtLocation(IProject project, IPath sourceLoc, int lineNumber) {
    IEditorInput input = this.getEditorInput();
    if (input instanceof STAnnotatedSourceNotFoundEditorInput) {
        STAnnotatedSourceNotFoundEditorInput editorInput = (STAnnotatedSourceNotFoundEditorInput) input;
        SourceFile sf = editorInput.getSourceFile();
        OpenSourceFileAction.openAnnotatedSourceFile(project, null, sf, sourceLoc, lineNumber);
    } else {
        super.openSourceFileAtLocation(project, sourceLoc, lineNumber);
    }
}
Also used : SourceFile(org.eclipse.linuxtools.internal.gcov.parser.SourceFile) IEditorInput(org.eclipse.ui.IEditorInput)

Aggregations

SourceFile (org.eclipse.linuxtools.internal.gcov.parser.SourceFile)4 IFile (org.eclipse.core.resources.IFile)3 IProject (org.eclipse.core.resources.IProject)3 Path (org.eclipse.core.runtime.Path)3 CovManager (org.eclipse.linuxtools.internal.gcov.parser.CovManager)3 IOException (java.io.IOException)2 IWorkspaceRoot (org.eclipse.core.resources.IWorkspaceRoot)2 CoreException (org.eclipse.core.runtime.CoreException)2 IPath (org.eclipse.core.runtime.IPath)2 URI (java.net.URI)1 ArrayList (java.util.ArrayList)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 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 CovFileTreeElement (org.eclipse.linuxtools.internal.gcov.model.CovFileTreeElement)1 CovFunctionTreeElement (org.eclipse.linuxtools.internal.gcov.model.CovFunctionTreeElement)1 TreeElement (org.eclipse.linuxtools.internal.gcov.model.TreeElement)1 IEditorInput (org.eclipse.ui.IEditorInput)1