Search in sources :

Example 26 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class ImportTracePackageWizardPage method promptForExperimentOverwrite.

private int promptForExperimentOverwrite(Entry<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentEntry, List<TracePackageExperimentElement> experimentToRename) {
    List<TracePackageTraceElement> traceElements = experimentEntry.getValue();
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < traceElements.size(); i++) {
        builder.append(traceElements.get(i).getImportName());
        if (i < traceElements.size() - 1) {
            // $NON-NLS-1$
            builder.append(", ");
        }
    }
    String dialogMessage;
    if (experimentToRename.contains(experimentEntry.getKey())) {
        dialogMessage = MessageFormat.format(Messages.ImportTracePackageWizardPage_ExperimentAndTraceAlreadyExist, experimentEntry.getKey().getImportName(), builder.toString());
    } else {
        dialogMessage = MessageFormat.format(Messages.ImportTracePackageWizardPage_TraceFromExperimentAlreadyExist, experimentEntry.getKey().getImportName(), builder.toString());
    }
    final MessageDialog dialog = new MessageDialog(getContainer().getShell(), Messages.ImportTracePackageWizardPage_AlreadyExistsTitle, null, dialogMessage, MessageDialog.QUESTION, new String[] { IDialogConstants.NO_LABEL, IDialogConstants.YES_LABEL }, 3) {

        @Override
        protected int getShellStyle() {
            return super.getShellStyle() | SWT.SHEET;
        }
    };
    return dialog.open();
}
Also used : TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) MessageDialog(org.eclipse.jface.dialogs.MessageDialog)

Example 27 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class AbstractGenerateManifestOperation method generatePatterns.

/**
 * Generates regular expression patterns from the template element.
 *
 * @param templateElements
 *            input template elements
 * @return map of generated {@link Pattern} to corresponding
 *         {@link TracePackageFilesElement}
 */
protected Map<Pattern, TracePackageTraceElement> generatePatterns(TracePackageElement[] templateElements) {
    Map<Pattern, TracePackageTraceElement> templatePatterns = new HashMap<>();
    for (TracePackageElement templateElement : templateElements) {
        if (templateElement instanceof TracePackageTraceElement) {
            TracePackageElement[] children = templateElement.getChildren();
            if (children != null) {
                for (TracePackageElement child : children) {
                    if (child instanceof TracePackageFilesElement) {
                        TracePackageFilesElement tracePackageFilesElement = (TracePackageFilesElement) child;
                        Pattern pattern = Pattern.compile(tracePackageFilesElement.getFileName());
                        templatePatterns.put(pattern, (TracePackageTraceElement) templateElement);
                    }
                }
            }
        }
    }
    return templatePatterns;
}
Also used : Pattern(java.util.regex.Pattern) HashMap(java.util.HashMap) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 28 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteGenerateManifestOperation method filterElements.

/*
     * Filter elements to avoid having files of directory traces listed as
     * separate traces.
     */
private void filterElements(TracePackageElement parentElement) {
    for (TracePackageElement childElement : parentElement.getChildren()) {
        filterElements(childElement);
        if (childElement instanceof TracePackageTraceElement) {
            // no need to do length check here
            RemoteImportTraceFilesElement filesElement = (RemoteImportTraceFilesElement) childElement.getChildren()[0];
            IFileStore parentFile = filesElement.getRemoteFile().getParent();
            if (fDirectoryTraces.contains(TmfTraceCoreUtils.newSafePath(parentFile.toURI().getPath()))) {
                removeChild(childElement, parentElement);
                continue;
            }
            IFileStore grandParentFile = parentFile.getParent();
            if (grandParentFile != null && fDirectoryTraces.contains(TmfTraceCoreUtils.newSafePath(grandParentFile.toURI().getPath()))) {
                // ignore file if grandparent is a directory trace
                // for example: file is a index file of a LTTng kernel trace
                parentElement.removeChild(childElement);
                if (parentElement.getChildren().length == 0) {
                    TracePackageElement grandParentElement = parentElement.getParent();
                    removeChild(parentElement, grandParentElement);
                }
                continue;
            }
        } else if (childElement instanceof RemoteImportFolderElement) {
            if (childElement.getChildren().length == 0) {
                parentElement.removeChild(childElement);
            }
        }
    }
}
Also used : TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) IFileStore(org.eclipse.core.filesystem.IFileStore) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 29 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteGenerateManifestOperation method generateElementsFromArchive.

// ------------------------------------------------------------------------
// Helper methods
// ------------------------------------------------------------------------
/**
 * Scan traceFolder for files that match the patterns specified in the
 * template file. When there is a match, the trace package element is used
 * to determine the trace name and trace type.
 *
 * @param traceGroup
 *                The parent trace group element
 * @param parentElement
 *                The immediate parent trace group or folder element
 * @param traceFolder
 *                The folder to scan
 * @param recursionLevel
 *                The recursion level (needed to find directory traces under the traceFolder
 * @param monitor
 *                The progress monitor
 * @throws CoreException
 *                Thrown by the file system implementation
 * @throws InterruptedException
 *                Thrown if operation was cancelled
 */
private void generateElementsFromArchive(final RemoteImportTraceGroupElement traceGroup, final TracePackageElement parentElement, final IFileStore traceFolder, final int recursionLevel, IProgressMonitor monitor) throws CoreException, InterruptedException {
    int localRecursionLevel = recursionLevel + 1;
    IFileStore[] sources = traceFolder.childStores(EFS.NONE, monitor);
    for (int i = 0; i < sources.length; i++) {
        ModalContext.checkCanceled(monitor);
        SubMonitor subMonitor = SubMonitor.convert(monitor, sources.length);
        IFileStore fileStore = sources[i];
        IPath fullArchivePath = TmfTraceCoreUtils.newSafePath(fileStore.toURI().getPath());
        IFileInfo sourceInfo = fileStore.fetchInfo();
        if (!sourceInfo.isDirectory()) {
            String rootPathString = traceGroup.getRootImportPath();
            IPath rootPath = TmfTraceCoreUtils.newSafePath(rootPathString);
            IPath relativeTracePath = Path.EMPTY;
            if (rootPath.isPrefixOf(fullArchivePath)) {
                relativeTracePath = fullArchivePath.makeRelativeTo(rootPath);
            }
            Entry<Pattern, TracePackageTraceElement> matchingTemplateEntry = getMatchingTemplateElement(relativeTracePath);
            if (matchingTemplateEntry != null) {
                TracePackageTraceElement matchingTemplateElement = matchingTemplateEntry.getValue();
                String traceType = matchingTemplateElement.getTraceType();
                // If a single file is part of a directory trace, use the parent directory instead
                TracePackageElement parent = parentElement;
                if (matchesDirectoryTrace(relativeTracePath, matchingTemplateEntry)) {
                    fullArchivePath = fullArchivePath.removeLastSegments(1);
                    fDirectoryTraces.add(fullArchivePath);
                    fileStore = fileStore.getParent();
                    sourceInfo = fileStore.fetchInfo();
                    parent = parentElement.getParent();
                    // Let the auto-detection choose the best trace type
                    traceType = null;
                } else if ((localRecursionLevel > 1) && (!traceGroup.isRecursive())) {
                    // Don't consider file traces on level 2 if it's not recursive
                    continue;
                }
                if (sourceInfo.getLength() > 0 || sourceInfo.isDirectory()) {
                    // Only add non-empty files
                    String traceName = fullArchivePath.lastSegment();
                    String fileName = fileStore.getName();
                    // create new elements to decouple from input elements
                    TracePackageTraceElement traceElement = new TracePackageTraceElement(parent, traceName, traceType);
                    RemoteImportTraceFilesElement tracePackageFilesElement = new RemoteImportTraceFilesElement(traceElement, fileName, fileStore);
                    tracePackageFilesElement.setVisible(false);
                }
            }
        } else {
            if (traceGroup.isRecursive() || localRecursionLevel < 2) {
                RemoteImportFolderElement folder = new RemoteImportFolderElement(parentElement, fileStore.getName());
                generateElementsFromArchive(traceGroup, folder, fileStore, localRecursionLevel, subMonitor);
            }
        }
    }
}
Also used : Pattern(java.util.regex.Pattern) IPath(org.eclipse.core.runtime.IPath) SubMonitor(org.eclipse.core.runtime.SubMonitor) IFileInfo(org.eclipse.core.filesystem.IFileInfo) IFileStore(org.eclipse.core.filesystem.IFileStore) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 30 with TracePackageTraceElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement in project tracecompass by tracecompass.

the class RemoteImportProfilesWriter method exportTrace.

private static void exportTrace(Node traceGroupNode, TracePackageTraceElement trace) {
    Element traceElement = traceGroupNode.getOwnerDocument().createElement(ITracePackageConstants.TRACE_ELEMENT);
    traceElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB, trace.getImportName());
    traceElement.setAttribute(ITracePackageConstants.TRACE_TYPE_ATTRIB, trace.getTraceType());
    for (TracePackageElement files : trace.getChildren()) {
        if (files instanceof TracePackageFilesElement) {
            exportTraceFiles(traceElement, (TracePackageFilesElement) files);
            break;
        }
    }
    traceGroupNode.appendChild(traceElement);
}
Also used : TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) Element(org.w3c.dom.Element) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)

Aggregations

TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)32 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)23 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)22 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)9 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)9 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)9 ArrayList (java.util.ArrayList)8 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)8 Element (org.w3c.dom.Element)7 IPath (org.eclipse.core.runtime.IPath)6 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)6 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)6 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)6 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)6 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)6 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)6 Path (org.eclipse.core.runtime.Path)4 Node (org.w3c.dom.Node)4 URI (java.net.URI)3 HashMap (java.util.HashMap)3