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);
}
}
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);
}
}
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;
}
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;
}
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);
}
}
}
}
Aggregations