Search in sources :

Example 6 with TracePackageExperimentElement

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

the class TracePackageImportOperation method doRun.

private void doRun(IProgressMonitor progressMonitor) {
    try {
        setStatus(deleteExistingTraces(progressMonitor));
        if (!getStatus().isOK()) {
            return;
        }
        List<TracePackageExperimentElement> experimentPackageElements = new ArrayList<>();
        for (TracePackageElement packageElement : fImportTraceElements) {
            TracePackageTraceElement traceElement = (TracePackageTraceElement) packageElement;
            if (!isFilesChecked(packageElement)) {
                continue;
            }
            if (packageElement instanceof TracePackageExperimentElement) {
                experimentPackageElements.add((TracePackageExperimentElement) packageElement);
                continue;
            }
            TracePackageElement[] children = traceElement.getChildren();
            for (TracePackageElement element : children) {
                ModalContext.checkCanceled(progressMonitor);
                if (element instanceof TracePackageFilesElement) {
                    TracePackageFilesElement traceFilesElement = (TracePackageFilesElement) element;
                    setStatus(importTraceFiles(traceFilesElement, traceElement, progressMonitor));
                }
                if (!getStatus().isOK()) {
                    return;
                }
            }
            setStatus(importSupplFiles(traceElement, progressMonitor));
            if (!getStatus().isOK()) {
                return;
            }
        }
        for (TracePackageExperimentElement experimentPackageElement : experimentPackageElements) {
            ModalContext.checkCanceled(progressMonitor);
            importExperiment(experimentPackageElement, progressMonitor);
            if (!getStatus().isOK()) {
                return;
            }
        }
    } catch (InterruptedException e) {
        setStatus(Status.CANCEL_STATUS);
        Thread.currentThread().interrupt();
    }
}
Also used : TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) ArrayList(java.util.ArrayList) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 7 with TracePackageExperimentElement

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

the class TracePackageImportOperation method importSupplFiles.

private IStatus importSupplFiles(TracePackageTraceElement packageElement, IProgressMonitor monitor) {
    List<Pair<String, String>> fileNameAndLabelPairs = new ArrayList<>();
    Map<String, String> suppFilesRename = new HashMap<>();
    for (TracePackageElement element : packageElement.getChildren()) {
        if (element instanceof TracePackageSupplFilesElement) {
            for (TracePackageElement child : element.getChildren()) {
                if (child.isChecked()) {
                    TracePackageSupplFileElement supplFile = (TracePackageSupplFileElement) child;
                    if (packageElement instanceof TracePackageExperimentElement) {
                        String oldExpName = getOldExpName(supplFile);
                        if (!packageElement.getImportName().equals(oldExpName)) {
                            suppFilesRename.put(supplFile.getText(), supplFile.getText().replace(oldExpName, packageElement.getImportName()));
                        }
                    }
                    fileNameAndLabelPairs.add(new Pair<>(checkNotNull(supplFile.getText()), checkNotNull(new Path(supplFile.getText()).lastSegment())));
                }
            }
        }
    }
    if (!fileNameAndLabelPairs.isEmpty()) {
        TmfCommonProjectElement projectElement = getMatchingProjectElement(packageElement);
        if (projectElement != null) {
            ArchiveFile archiveFile = getSpecifiedArchiveFile();
            projectElement.refreshSupplementaryFolder();
            IPath destinationContainerPath;
            if (packageElement instanceof TracePackageExperimentElement) {
                destinationContainerPath = projectElement.getProject().getSupplementaryFolder().getFullPath();
            } else {
                // Project/Traces/A/B -> A/B
                final TmfTraceFolder tracesFolder = fTmfTraceFolder.getProject().getTracesFolder();
                if (tracesFolder == null) {
                    return new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation);
                }
                IPath traceFolderRelativePath = fTmfTraceFolder.getPath().makeRelativeTo(tracesFolder.getPath());
                // Project/.tracing/A/B/
                IFolder traceSupplementaryFolder = fTmfTraceFolder.getTraceSupplementaryFolder(traceFolderRelativePath.toString());
                destinationContainerPath = traceSupplementaryFolder.getFullPath();
            }
            // Remove the .tracing segment at the beginning so that a file
            // in folder .tracing/A/B/ imports to destinationContainerPath/A/B/
            Path baseSourcePath = new Path(TmfCommonConstants.TRACE_SUPPLEMENTARY_FOLDER_NAME);
            return importFiles(archiveFile, fileNameAndLabelPairs, destinationContainerPath, baseSourcePath, suppFilesRename, monitor);
        }
    }
    return Status.OK_STATUS;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IPath(org.eclipse.core.runtime.IPath) HashMap(java.util.HashMap) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) ArrayList(java.util.ArrayList) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceFolder(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceFolder) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Pair(org.eclipse.tracecompass.tmf.core.util.Pair) IFolder(org.eclipse.core.resources.IFolder)

Example 8 with TracePackageExperimentElement

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

the class TracePackageExportOperation method exportExperiment.

private void exportExperiment(IProgressMonitor monitor, Node tmfNode, TracePackageExperimentElement experimentPackageElement) throws InterruptedException, CoreException {
    Node expNode = exportCommon(monitor, tmfNode, experimentPackageElement, ITracePackageConstants.EXPERIMENT_ELEMENT);
    TmfExperimentElement experimentElement = (TmfExperimentElement) experimentPackageElement.getTraceElement();
    for (TmfTraceElement traceElement : experimentElement.getTraces()) {
        Element expTraceXmlElement = expNode.getOwnerDocument().createElement(ITracePackageConstants.EXP_TRACE_ELEMENT);
        expTraceXmlElement.setAttribute(ITracePackageConstants.TRACE_NAME_ATTRIB, traceElement.getElementPath());
        expNode.appendChild(expTraceXmlElement);
    }
}
Also used : TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) Node(org.w3c.dom.Node) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)

Example 9 with TracePackageExperimentElement

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

the class TracePackageExportOperation method run.

/**
 * Run the operation. The status (result) of the operation can be obtained
 * with {@link #getStatus}
 *
 * @param progressMonitor
 *            the progress monitor to use to display progress and receive
 *            requests for cancellation
 */
@Override
public void run(IProgressMonitor progressMonitor) {
    try {
        int totalWork = getNbCheckedElements(fTraceExportElements) * 2;
        progressMonitor.beginTask(Messages.TracePackageExportOperation_GeneratingPackage, totalWork);
        fExportFolder = createExportFolder(progressMonitor);
        Document doc = XmlUtils.newSafeDocumentBuilderFactory().newDocumentBuilder().newDocument();
        Element createElement = doc.createElement(ITracePackageConstants.TMF_EXPORT_ELEMENT);
        Node tmfNode = doc.appendChild(createElement);
        List<TracePackageExperimentElement> experimentPackageElements = new ArrayList<>();
        for (TracePackageTraceElement tracePackageElement : fTraceExportElements) {
            if (!isFilesChecked(tracePackageElement)) {
                continue;
            }
            if (tracePackageElement instanceof TracePackageExperimentElement) {
                experimentPackageElements.add((TracePackageExperimentElement) tracePackageElement);
            } else {
                exportTrace(progressMonitor, tmfNode, tracePackageElement);
            }
        }
        for (TracePackageExperimentElement experimentPackageElement : experimentPackageElements) {
            exportExperiment(progressMonitor, tmfNode, experimentPackageElement);
        }
        Transformer transformer = XmlUtils.newSecureTransformer();
        // $NON-NLS-1$
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        // $NON-NLS-1$ //$NON-NLS-2$
        transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "4");
        DOMSource source = new DOMSource(doc);
        StringWriter buffer = new StringWriter();
        StreamResult result = new StreamResult(buffer);
        transformer.transform(source, result);
        String content = buffer.getBuffer().toString();
        ModalContext.checkCanceled(progressMonitor);
        exportManifest(content);
        setStatus(exportToArchive(progressMonitor, totalWork));
        fExportFolder.delete(true, SubMonitor.convert(progressMonitor));
        progressMonitor.done();
    } catch (InterruptedException e) {
        setStatus(Status.CANCEL_STATUS);
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.Messages.TracePackage_ErrorOperation, e));
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) DOMSource(javax.xml.transform.dom.DOMSource) Transformer(javax.xml.transform.Transformer) StreamResult(javax.xml.transform.stream.StreamResult) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TmfCommonProjectElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TmfProjectModelElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfProjectModelElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) TracePackageSupplFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement) TmfTraceElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement) TmfExperimentElement(org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement) TracePackageSupplFileElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement) Element(org.w3c.dom.Element) TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageBookmarkElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList) Document(org.w3c.dom.Document) CoreException(org.eclipse.core.runtime.CoreException) InvocationTargetException(java.lang.reflect.InvocationTargetException) StringWriter(java.io.StringWriter) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Example 10 with TracePackageExperimentElement

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

the class ImportTracePackageWizardPage method processTrace.

private void processTrace(List<TracePackageExperimentElement> experimentElements, TracePackageTraceElement traceElement, Map<TracePackageExperimentElement, List<TracePackageTraceElement>> experimentTracesMap, List<TracePackageTraceElement> unhandledTraces) {
    boolean isAlone = traceExists(traceElement);
    for (TracePackageExperimentElement experimentElement : experimentElements) {
        List<String> tracesPath = experimentElement.getExpTraces();
        if (traceExists(traceElement) && tracesPath.contains(traceElement.getDestinationElementPath())) {
            isAlone = false;
            List<TracePackageTraceElement> traces = experimentTracesMap.get(experimentElement);
            if (traces == null) {
                traces = new ArrayList<>();
            }
            traces.add(traceElement);
            experimentTracesMap.put(experimentElement, traces);
        }
    }
    if (isAlone) {
        unhandledTraces.add(traceElement);
    }
}
Also used : TracePackageExperimentElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)

Aggregations

TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)10 ArrayList (java.util.ArrayList)7 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)7 TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)6 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)5 TracePackageSupplFileElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFileElement)5 TracePackageSupplFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageSupplFilesElement)5 TracePackageBookmarkElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageBookmarkElement)4 TmfCommonProjectElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfCommonProjectElement)4 TmfExperimentElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfExperimentElement)4 TmfTraceElement (org.eclipse.tracecompass.tmf.ui.project.model.TmfTraceElement)4 HashMap (java.util.HashMap)3 IPath (org.eclipse.core.runtime.IPath)3 Element (org.w3c.dom.Element)3 Node (org.w3c.dom.Node)3 List (java.util.List)2 IFolder (org.eclipse.core.resources.IFolder)2 CoreException (org.eclipse.core.runtime.CoreException)2 IStatus (org.eclipse.core.runtime.IStatus)2 Path (org.eclipse.core.runtime.Path)2