use of org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement in project tracecompass by tracecompass.
the class ImportHandler method execute.
// ------------------------------------------------------------------------
// Operations
// ------------------------------------------------------------------------
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
if (window == null) {
return false;
}
CommandParameter param;
fLock.lock();
try {
param = fParam;
if (param == null) {
return null;
}
param = param.clone();
} finally {
fLock.unlock();
}
// create default project
IProject project = TmfProjectRegistry.createProject(RemoteFetchLogWizardRemotePage.DEFAULT_REMOTE_PROJECT_NAME, null, null);
if (param.getSession().isLiveTrace()) {
importLiveTrace(new LttngRelaydConnectionInfo(param.getSession().getLiveUrl(), param.getSession().getLivePort(), param.getSession().getName()), project);
return null;
} else if (param.getSession().isStreamedTrace()) {
IPreferenceStore store = Activator.getDefault().getPreferenceStore();
String notify = store.getString(NOTIFY_IMPORT_STREAMED_PREF_KEY);
if (!MessageDialogWithToggle.ALWAYS.equals(notify)) {
MessageDialogWithToggle.openInformation(window.getShell(), null, Messages.TraceControl_ImportDialogStreamedTraceNotification, Messages.TraceControl_ImportDialogStreamedTraceNotificationToggle, false, store, NOTIFY_IMPORT_STREAMED_PREF_KEY);
}
// Streamed trace
TmfProjectElement projectElement = TmfProjectRegistry.getProject(project, true);
TmfTraceFolder traceFolder = projectElement.getTracesFolder();
ImportTraceWizard wizard = new ImportTraceWizard();
wizard.init(PlatformUI.getWorkbench(), new StructuredSelection(traceFolder));
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
return null;
}
// Generate the profile
TraceSessionComponent session = param.getSession();
// $NON-NLS-1$
RemoteImportProfileElement profile = new RemoteImportProfileElement(null, "LTTng Remote Traces");
RemoteSystemProxy proxy = session.getTargetNode().getRemoteSystemProxy();
IRemoteConnection rc = proxy.getRemoteConnection();
String name = rc.getName();
if (!rc.hasService(IRemoteConnectionHostService.class)) {
return null;
}
String scheme = rc.getConnectionType().getScheme();
IRemoteConnectionHostService hostService = checkNotNull(rc.getService(IRemoteConnectionHostService.class));
String address = hostService.getHostname();
String user = hostService.getUsername();
int port = hostService.getPort();
URI remoteUri;
try {
remoteUri = new URI(scheme, user, address, port, null, null, null);
} catch (URISyntaxException e) {
return false;
}
RemoteImportConnectionNodeElement connection = new RemoteImportConnectionNodeElement(profile, name, remoteUri.toString());
String pathString = session.isSnapshotSession() ? session.getSnapshotInfo().getSnapshotPath() : session.getSessionPath();
IPath path = new Path(pathString);
RemoteImportTraceGroupElement group = new RemoteImportTraceGroupElement(connection, path.toString());
group.setRecursive(true);
// $NON-NLS-1$//$NON-NLS-2$
TracePackageElement element = new TracePackageTraceElement(group, "", "");
// $NON-NLS-1$
new TracePackageFilesElement(element, ".*");
String experimentName = path.lastSegment();
if (!experimentName.startsWith(session.getName())) {
experimentName = session.getName();
}
RemoteFetchLogWizard wizard = new RemoteFetchLogWizard(profile, experimentName);
wizard.init(PlatformUI.getWorkbench(), StructuredSelection.EMPTY);
WizardDialog dialog = new WizardDialog(window.getShell(), wizard);
dialog.open();
return null;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement 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.ui.project.model.TmfProjectElement in project tracecompass by tracecompass.
the class XMLAnalysesManagerPreferencePage method deleteSupplementaryFiles.
/**
* Delete the supplementary files associated with XML analysis files.
*
* @param xmlFiles
* the xml analysis files (with extension)
* @return the list of elements that should be re-opened
*/
private static Collection<TmfCommonProjectElement> deleteSupplementaryFiles(Collection<String> xmlFiles) {
// 1. Look for all traces that have these analyses
// 2. Close them if they are opened, but remember them
// 3. Delete the related supplementary files
Collection<TmfCommonProjectElement> toReopen = new ArrayList<>();
List<IResource> resourceToDelete = new ArrayList<>();
Set<String> ids = Sets.newHashSet();
xmlFiles.forEach(xmlFile -> ids.addAll(XmlUtils.getAnalysisIdsFromFile(xmlFile)));
IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects(0);
for (IProject project : projects) {
TmfProjectElement pElement = TmfProjectRegistry.getProject(project);
if (pElement != null) {
List<TmfCommonProjectElement> tElements = new ArrayList<>();
TmfTraceFolder tracesFolder = pElement.getTracesFolder();
if (tracesFolder != null) {
tElements.addAll(tracesFolder.getTraces());
}
TmfExperimentFolder experimentsFolder = pElement.getExperimentsFolder();
if (experimentsFolder != null) {
tElements.addAll(experimentsFolder.getExperiments());
}
Set<IEditorReference> editorReferences = getEditorReferences();
for (TmfCommonProjectElement tElement : tElements) {
for (IResource resource : tElement.getSupplementaryResources()) {
for (String id : ids) {
if (resource.getName().startsWith(id)) {
resourceToDelete.add(resource);
}
}
}
IFile file = tElement.getBookmarksFile();
FileEditorInput input = new FileEditorInput(file);
boolean open = Iterables.any(editorReferences, editorReference -> {
try {
return editorReference.getEditorInput().equals(input);
} catch (PartInitException e) {
// $NON-NLS-1$ //$NON-NLS-2$
Activator.logError("Failed to test the " + tElement.getName() + " editor", e);
return false;
}
});
if (open) {
toReopen.add(tElement);
}
tElement.closeEditors();
}
}
}
for (IResource resource : resourceToDelete) {
try {
resource.delete(false, null);
} catch (CoreException e) {
Activator.logError(NLS.bind(Messages.ManageXMLAnalysisDialog_DeleteFileError, resource.getName()));
}
}
return toReopen;
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement in project tracecompass by tracecompass.
the class FetchRemoteTracesTest method test_8_13.
/**
* Test 8.13: Run Profile "TestSpecificMultiGroupRecursive"
*/
@Test
public void test_8_13() {
SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
projectExplorerBot.show();
SWTBotTreeItem tracesFolderItem = getTracesFolderTreeItem(projectExplorerBot);
tracesFolderItem.contextMenu(FETCH_COMMAND_NAME).click();
SWTBotShell shell = fBot.shell(FETCH_SHELL_NAME).activate();
fBot.comboBox().setSelection("TestSpecificMultiGroupRecursive");
fBot.button("Next >").click();
fBot.button("Finish").click();
fBot.waitUntil(Conditions.shellCloses(shell), FETCH_TIME_OUT);
WaitUtils.waitForJobs();
TmfProjectElement project = TmfProjectRegistry.getProject(ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME), true);
fBot.waitUntil(new TraceCountCondition(project, 2));
final TmfTraceFolder tracesFolder = project.getTracesFolder();
assertNotNull(tracesFolder);
List<TmfTraceElement> traces = tracesFolder.getTraces();
assertEquals(2, traces.size());
testTrace(traces.get(0), CONNECTION_NODE1_NAME + "/resources/generated/synthetic-trace", TRACE_TYPE_KERNEL);
testTrace(traces.get(1), CONNECTION_NODE1_NAME + "/resources/syslog", TRACE_TYPE_SYSLOG);
}
use of org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectElement in project tracecompass by tracecompass.
the class FetchRemoteTracesTest method test_8_06.
/**
* Test 8.6: Re-Run Profile "TestAllRecursive" (Overwrite)
*
* @throws CoreException if an exception occurs
*/
@Test
public void test_8_06() throws CoreException {
SWTBotView projectExplorerBot = fBot.viewByTitle(PROJECT_EXPLORER);
projectExplorerBot.show();
SWTBotTreeItem tracesFolderItem = getTracesFolderTreeItem(projectExplorerBot);
tracesFolderItem.contextMenu(FETCH_COMMAND_NAME).click();
SWTBotShell shell = fBot.shell(FETCH_SHELL_NAME).activate();
fBot.comboBox().setSelection("TestAllRecursive");
fBot.button("Next >").click();
fBot.button("Finish").click();
fBot.waitUntil(Conditions.shellCloses(shell), FETCH_TIME_OUT);
WaitUtils.waitForJobs();
TmfProjectElement project = TmfProjectRegistry.getProject(ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME), true);
fBot.waitUntil(new TraceCountCondition(project, 3));
final TmfTraceFolder tracesFolder = project.getTracesFolder();
assertNotNull(tracesFolder);
for (TmfTraceElement traceElement : tracesFolder.getTraces()) {
traceElement.getResource().setPersistentProperty(ORIGINAL, Boolean.TRUE.toString());
}
tracesFolderItem.contextMenu(FETCH_COMMAND_NAME).click();
shell = fBot.shell(FETCH_SHELL_NAME).activate();
fBot.comboBox().setSelection("TestAllRecursive");
fBot.button("Next >").click();
fBot.button("Finish").click();
fBot.shell(CONFIRMATION_SHELL_NAME).activate();
fBot.button("Overwrite").click();
fBot.shell(CONFIRMATION_SHELL_NAME).activate();
fBot.button("Overwrite All").click();
fBot.waitUntil(Conditions.shellCloses(shell), FETCH_TIME_OUT);
WaitUtils.waitForJobs();
fBot.waitUntil(new TraceCountCondition(project, 3));
List<TmfTraceElement> traces = tracesFolder.getTraces();
assertEquals(3, traces.size());
testTrace(traces.get(0), CONNECTION_NODE1_NAME + "/resources/generated/synthetic-trace", TRACE_TYPE_KERNEL);
testTrace(traces.get(1), CONNECTION_NODE1_NAME + "/resources/syslog", TRACE_TYPE_SYSLOG);
testTrace(traces.get(2), CONNECTION_NODE1_NAME + "/resources/unrecognized", null);
// Verify overwritten traces lost the original property
for (TmfTraceElement traceElement : traces) {
assertNull(traceElement.getResource().getPersistentProperty(ORIGINAL));
}
}
Aggregations