use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.
the class ImportHandler method initializeTraceResource.
private static void initializeTraceResource(final LttngRelaydConnectionInfo connectionInfo, final String tracePath, final IProject project) throws CoreException, TmfTraceImportException {
final TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
final TmfTraceFolder tracesFolder = projectElement.getTracesFolder();
if (tracesFolder != null) {
IFolder folder = tracesFolder.getResource();
IFolder traceFolder = folder.getFolder(connectionInfo.getSessionName());
Path location = new Path(tracePath);
IStatus result = ResourcesPlugin.getWorkspace().validateLinkLocation(folder, location);
if (result.isOK()) {
traceFolder.createLink(location, IResource.REPLACE, new NullProgressMonitor());
} else {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, result.getMessage()));
}
TraceTypeHelper selectedTraceType = TmfTraceTypeUIUtils.selectTraceType(location.toOSString(), null, null);
// No trace type was determined.
TmfTraceTypeUIUtils.setTraceType(traceFolder, selectedTraceType);
TmfTraceElement found = null;
final List<TmfTraceElement> traces = tracesFolder.getTraces();
for (TmfTraceElement candidate : traces) {
if (candidate.getName().equals(connectionInfo.getSessionName())) {
found = candidate;
}
}
if (found == null) {
throw new CoreException(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TraceControl_LiveTraceElementError));
}
// Properties used to be able to reopen a trace in live mode
traceFolder.setPersistentProperty(CtfConstants.LIVE_HOST, connectionInfo.getHost());
traceFolder.setPersistentProperty(CtfConstants.LIVE_PORT, Integer.toString(connectionInfo.getPort()));
traceFolder.setPersistentProperty(CtfConstants.LIVE_SESSION_NAME, connectionInfo.getSessionName());
final TmfTraceElement finalTrace = found;
Display.getDefault().syncExec(() -> TmfOpenTraceHelper.openFromElement(finalTrace));
}
}
use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.
the class TmfAnalysisModuleHelperXml method appliesToTraceType.
@Override
public boolean appliesToTraceType(Class<? extends ITmfTrace> traceClass) {
/* Trace types may be available in XML header */
List<Element> head = TmfXmlUtils.getChildElements(fSourceElement, TmfXmlStrings.HEAD);
if (head.size() != 1) {
return true;
}
/*
* TODO: Test with custom trace types
*/
List<Element> elements = TmfXmlUtils.getChildElements(head.get(0), TmfXmlStrings.TRACETYPE);
if (elements.isEmpty()) {
return true;
}
for (Element element : elements) {
String traceTypeId = element.getAttribute(TmfXmlStrings.ID);
traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
if ((helper != null) && helper.getTrace().getClass().isAssignableFrom(traceClass)) {
return true;
}
}
return false;
}
use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.
the class TmfFilterContentHandler method startElement.
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
ITmfFilterTreeNode node = null;
if (localName.equalsIgnoreCase(TmfFilterRootNode.NODE_NAME)) {
node = new TmfFilterRootNode();
} else if (localName.equals(TmfFilterNode.NODE_NAME)) {
node = new TmfFilterNode(atts.getValue(TmfFilterNode.NAME_ATTR));
} else if (localName.equals(TmfFilterTraceTypeNode.NODE_NAME)) {
node = new TmfFilterTraceTypeNode(null);
String traceTypeId = atts.getValue(TmfFilterTraceTypeNode.TYPE_ATTR);
traceTypeId = TmfTraceType.buildCompatibilityTraceTypeId(traceTypeId);
((TmfFilterTraceTypeNode) node).setTraceTypeId(traceTypeId);
TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
if (helper != null) {
((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
}
((TmfFilterTraceTypeNode) node).setName(atts.getValue(TmfFilterTraceTypeNode.NAME_ATTR));
} else if (localName.equals(TmfFilterAndNode.NODE_NAME)) {
node = new TmfFilterAndNode(null);
} else if (localName.equals(TmfFilterOrNode.NODE_NAME)) {
node = new TmfFilterOrNode(null);
} else if (localName.equals(TmfFilterContainsNode.NODE_NAME)) {
node = new TmfFilterContainsNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
String value = atts.getValue(TmfFilterContainsNode.IGNORECASE_ATTR);
if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
((TmfFilterContainsNode) node).setIgnoreCase(true);
}
} else if (localName.equals(TmfFilterEqualsNode.NODE_NAME)) {
node = new TmfFilterEqualsNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
String value = atts.getValue(TmfFilterEqualsNode.IGNORECASE_ATTR);
if (value != null && value.equalsIgnoreCase(Boolean.TRUE.toString())) {
((TmfFilterEqualsNode) node).setIgnoreCase(true);
}
} else if (localName.equals(TmfFilterMatchesNode.NODE_NAME)) {
node = new TmfFilterMatchesNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
((TmfFilterMatchesNode) node).setRegex(atts.getValue(TmfFilterMatchesNode.REGEX_ATTR));
} else if (localName.equals(TmfFilterCompareNode.NODE_NAME)) {
node = new TmfFilterCompareNode(null);
createEventAspect((TmfFilterAspectNode) node, atts);
String value = atts.getValue(TmfFilterCompareNode.TYPE_ATTR);
if (value != null) {
((TmfFilterCompareNode) node).setType(Type.valueOf(value));
}
value = atts.getValue(TmfFilterCompareNode.RESULT_ATTR);
if (value != null) {
if (value.equals(Integer.toString(-1))) {
((TmfFilterCompareNode) node).setResult(-1);
} else if (value.equals(Integer.toString(1))) {
((TmfFilterCompareNode) node).setResult(1);
} else {
((TmfFilterCompareNode) node).setResult(0);
}
}
// Backward compatibility with event type filter node
} else if (localName.equals(EVENTTYPE_NODE_NAME)) {
node = new TmfFilterTraceTypeNode(null);
String label = atts.getValue(NAME_ATTR);
if (label != null) {
// Backward compatibility with renamed LTTng Kernel Trace
if (label.equals(LTTNG_KERNEL_TRACE)) {
label = LINUX_KERNEL_TRACE;
}
String traceTypeId = TmfTraceType.getTraceTypeId(label);
TraceTypeHelper helper = TmfTraceType.getTraceType(traceTypeId);
if (helper == null) {
// Backward compatibility with category-less custom trace types
for (TraceTypeHelper h : TmfTraceType.getTraceTypeHelpers()) {
if (h.getName().equals(label)) {
label = h.getLabel();
helper = h;
break;
}
}
}
if (helper != null) {
((TmfFilterTraceTypeNode) node).setTraceTypeId(helper.getTraceTypeId());
((TmfFilterTraceTypeNode) node).setTraceClass(helper.getTraceClass());
}
((TmfFilterTraceTypeNode) node).setName(label);
}
}
String value = atts.getValue(ITmfFilterWithNot.NOT_ATTRIBUTE);
if (node instanceof ITmfFilterWithNot && Boolean.TRUE.toString().equalsIgnoreCase(value)) {
((ITmfFilterWithNot) node).setNot(true);
}
if (node instanceof ITmfFilterWithValue) {
((ITmfFilterWithValue) node).setValue(atts.getValue(ITmfFilterWithValue.VALUE_ATTRIBUTE));
}
fFilterTreeStack.addFirst(node);
}
use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.
the class RemoteImportTracesOperation method doRun.
// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
private void doRun(IProgressMonitor monitor) throws ExecutionException, CoreException, IOException, InterruptedException {
IFolder destinationFolder = fDestination.getResource();
if (!destinationFolder.exists()) {
// $NON-NLS-1$//$NON-NLS-2$
throw new ExecutionException(RemoteMessages.RemoteImportTracesOperation_ImportDialogInvalidTracingProject + " (" + destinationFolder + ")");
}
SubMonitor subMonitor = SubMonitor.convert(monitor, fTraceElements.length * 4);
subMonitor.beginTask(RemoteMessages.RemoteImportTracesOperation_DownloadTask, fTraceElements.length * 4);
for (Object packageElement : fTraceElements) {
if (!(packageElement instanceof TracePackageTraceElement)) {
continue;
}
TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
TracePackageElement parentElement = traceElement.getParent();
while (parentElement != null) {
if (parentElement instanceof RemoteImportTraceGroupElement) {
break;
}
parentElement = parentElement.getParent();
}
if (parentElement == null) {
continue;
}
RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) parentElement;
String rootPath = traceGroup.getRootImportPath();
// Create folder with node name in destination folder
RemoteImportConnectionNodeElement nodeElement = (RemoteImportConnectionNodeElement) traceGroup.getParent();
String nodeName = nodeElement.getName();
IFolder nodeFolder = destinationFolder.getFolder(nodeName);
TracePackageElement[] children = traceElement.getChildren();
SubMonitor childMonitor = subMonitor.newChild(1);
TraceUtils.createFolder(nodeFolder, childMonitor);
for (TracePackageElement element : children) {
ModalContext.checkCanceled(monitor);
if (element instanceof RemoteImportTraceFilesElement) {
RemoteImportTraceFilesElement traceFilesElement = (RemoteImportTraceFilesElement) element;
IFileStore remoteFile = traceFilesElement.getRemoteFile();
// Preserve folder structure
IPath sessionParentPath = TmfTraceCoreUtils.newSafePath(rootPath).removeLastSegments(1);
IPath traceParentPath = TmfTraceCoreUtils.newSafePath(remoteFile.getParent().toURI().getPath());
IPath relativeTracePath = Path.EMPTY;
if (sessionParentPath.isPrefixOf(traceParentPath)) {
relativeTracePath = traceParentPath.makeRelativeTo(sessionParentPath);
}
String[] segments = relativeTracePath.segments();
for (int i = 0; i < segments.length; i++) {
String segment = TmfTraceCoreUtils.validateName(TmfTraceCoreUtils.safePathToString(segments[i]));
if (i == 0) {
relativeTracePath = new Path(segment);
} else {
relativeTracePath = relativeTracePath.append(segment);
}
}
IFolder traceFolder = nodeFolder.getFolder(new Path(relativeTracePath.toOSString()));
childMonitor = subMonitor.newChild(1);
TraceUtils.createFolder(traceFolder, childMonitor);
childMonitor.done();
// Import trace
IResource traceRes = null;
IFileInfo info = remoteFile.fetchInfo();
if (info.isDirectory()) {
traceRes = downloadDirectoryTrace(remoteFile, traceFolder, subMonitor.newChild(1));
} else {
traceRes = downloadFileTrace(remoteFile, traceFolder, subMonitor.newChild(1));
}
String traceName = traceElement.getText();
if (traceRes == null || !traceRes.exists()) {
continue;
}
// Select trace type
TraceTypeHelper traceTypeHelper = null;
String traceTypeStr = traceElement.getTraceType();
if (traceTypeStr != null) {
traceTypeHelper = TmfTraceType.getTraceType(traceTypeStr);
}
// no specific trace type found
if (traceTypeHelper == null) {
try {
// Try to auto-detect the trace typ
childMonitor = subMonitor.newChild(1);
childMonitor.setTaskName(NLS.bind(RemoteMessages.RemoteImportTracesOperation_DetectingTraceType, traceName));
childMonitor.done();
traceTypeHelper = TmfTraceTypeUIUtils.selectTraceType(traceRes.getLocation().toOSString(), null, null);
} catch (TmfTraceImportException e) {
// Could not figure out the type
}
}
if (traceTypeHelper != null) {
TmfTraceTypeUIUtils.setTraceType(traceRes, traceTypeHelper);
fImportedResources.add(traceRes);
}
// Set source location
URI uri = remoteFile.toURI();
String sourceLocation = URIUtil.toUnencodedString(uri);
traceRes.setPersistentProperty(TmfCommonConstants.SOURCE_LOCATION, sourceLocation);
}
}
}
}
use of org.eclipse.tracecompass.tmf.core.project.model.TraceTypeHelper in project tracecompass by tracecompass.
the class TraceValidateAndImportOperation method validateAndImportTrace.
/**
* Import a single file system element into the workspace.
*/
private void validateAndImportTrace(TraceFileSystemElement fileSystemElement, IProgressMonitor monitor) throws TmfTraceImportException, CoreException, InvocationTargetException, InterruptedException {
String path = fileSystemElement.getFileSystemObject().getAbsolutePath();
TraceTypeHelper traceTypeHelper = null;
// $NON-NLS-1$
monitor.setTaskName(Messages.ImportTraceWizard_ExamineOperationTaskName + " " + fileSystemElement.getFileSystemObject().getAbsolutePath());
if ((fImportOptionFlags & ImportTraceWizardPage.OPTION_SKIP_ARCHIVE_EXTRACTION) == 0) {
File file = (File) fileSystemElement.getFileSystemObject().getRawFileSystemObject();
boolean isArchiveFileElement = fileSystemElement.getFileSystemObject() instanceof FileFileSystemObject && ArchiveUtil.isArchiveFile(file);
if (isArchiveFileElement) {
// We'll be extracting this later, do not import as a trace
return;
}
}
if (fTraceType == null) {
// Auto Detection
try {
traceTypeHelper = TmfTraceTypeUIUtils.selectTraceType(path, null, null);
} catch (TmfTraceImportException e) {
// the trace did not match any trace type
}
if (traceTypeHelper == null) {
if ((fImportOptionFlags & ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES) != 0) {
importResource(fileSystemElement, monitor);
}
return;
}
} else {
boolean isDirectoryTraceType = TmfTraceType.isDirectoryTraceType(fTraceType);
if (fileSystemElement.isDirectory() != isDirectoryTraceType) {
return;
}
traceTypeHelper = TmfTraceType.getTraceType(fTraceType);
if (traceTypeHelper == null) {
// Trace type not found
throw new TmfTraceImportException(Messages.ImportTraceWizard_TraceTypeNotFound);
}
if (!traceTypeHelper.validate(path).isOK()) {
// Trace type exist but doesn't validate for given trace.
return;
}
}
// Finally import trace
TraceFileSystemElement resourceToImport = filterSelectedFileSystemElement(fileSystemElement, monitor);
if (resourceToImport == null) {
return;
}
IResource importedResource = importResource(resourceToImport, monitor);
if (importedResource != null) {
TmfTraceTypeUIUtils.setTraceType(importedResource, traceTypeHelper, false);
fImportedResources.add(importedResource);
}
}
Aggregations