Search in sources :

Example 21 with TracePackageElement

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

the class RemoteProfilesPreferencePage method validate.

private void validate() {
    setValid(false);
    Set<String> profileNames = new HashSet<>();
    for (RemoteImportProfileElement profile : fProfiles) {
        if (profile.getProfileName().length() == 0) {
            setErrorMessage(RemoteMessages.RemoteProfilesPreferencePage_EmptyProfileNameError);
            return;
        }
        // $NON-NLS-1$
        String prefix = profile.getProfileName() + ": ";
        if (!profileNames.add(profile.getProfileName())) {
            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_DuplicateProfileNameError);
            return;
        }
        Set<String> nodeNames = new HashSet<>();
        int nodeCount = 0;
        for (TracePackageElement profileChild : profile.getChildren()) {
            if (profileChild instanceof RemoteImportConnectionNodeElement) {
                nodeCount++;
                RemoteImportConnectionNodeElement node = (RemoteImportConnectionNodeElement) profileChild;
                if (node.getName().length() == 0) {
                    setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyNodeNameError);
                    return;
                }
                // validate node name against the OS since the name will be used as folder name at the destination
                if (!ResourcesPlugin.getWorkspace().validateName(node.getName(), IResource.FOLDER).isOK()) {
                    setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidNodeName);
                    return;
                }
                if (!nodeNames.add(node.getName())) {
                    setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_DuplicateConnectionNodeNameError);
                    return;
                }
                if (node.getURI().length() == 0) {
                    setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyNodeURIError);
                    return;
                }
                try {
                    URI uri = URIUtil.fromString(node.getURI());
                    IRemoteServicesManager manager = TmfRemoteConnectionFactory.getService(IRemoteServicesManager.class);
                    if (manager == null || manager.getConnectionType(uri) == null) {
                        setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_UnsupportedURISchemeError);
                        return;
                    }
                    if (uri.getScheme().equals(SSH_SCHEME)) {
                        if (uri.getHost() == null) {
                            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidHostOrPortError);
                            return;
                        }
                        if (uri.getUserInfo() == null) {
                            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingUserInfoError);
                            return;
                        }
                    }
                } catch (URISyntaxException e) {
                    setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidNodeURIError);
                    return;
                }
                int traceGroupCount = 0;
                for (TracePackageElement nodeChild : node.getChildren()) {
                    if (nodeChild instanceof RemoteImportTraceGroupElement) {
                        traceGroupCount++;
                        RemoteImportTraceGroupElement traceGroup = (RemoteImportTraceGroupElement) nodeChild;
                        if (traceGroup.getRootImportPath().length() == 0) {
                            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyRootPathError);
                            return;
                        }
                        int traceCount = 0;
                        for (TracePackageElement traceGroupChild : traceGroup.getChildren()) {
                            if (traceGroupChild instanceof TracePackageTraceElement) {
                                traceCount++;
                                TracePackageTraceElement trace = (TracePackageTraceElement) traceGroupChild;
                                for (TracePackageElement traceChild : trace.getChildren()) {
                                    if (traceChild instanceof TracePackageFilesElement) {
                                        TracePackageFilesElement files = (TracePackageFilesElement) traceChild;
                                        if (files.getFileName().length() == 0) {
                                            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_EmptyFilePatternError);
                                            return;
                                        }
                                        try {
                                            Pattern.compile(files.getFileName());
                                        } catch (PatternSyntaxException e) {
                                            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_InvalidFilePatternError);
                                            return;
                                        }
                                    }
                                }
                            }
                        }
                        if (traceCount == 0) {
                            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingTraceError);
                            return;
                        }
                    }
                }
                if (traceGroupCount == 0) {
                    setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingTraceGroupError);
                    return;
                }
            }
        }
        if (nodeCount == 0) {
            setErrorMessage(prefix + RemoteMessages.RemoteProfilesPreferencePage_MissingConnectionNodeError);
            return;
        }
    }
    setValid(true);
    setErrorMessage(null);
}
Also used : RemoteImportConnectionNodeElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement) TracePackageFilesElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement) IRemoteServicesManager(org.eclipse.remote.core.IRemoteServicesManager) URISyntaxException(java.net.URISyntaxException) RemoteImportTraceGroupElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement) RemoteImportProfileElement(org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement) URI(java.net.URI) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement) TracePackageTraceElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement) HashSet(java.util.HashSet) PatternSyntaxException(java.util.regex.PatternSyntaxException)

Example 22 with TracePackageElement

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

the class TracePackageExtractManifestOperation method generateElementsFromArchive.

private TracePackageElement[] generateElementsFromArchive() {
    ArchiveFile archiveFile = getSpecifiedArchiveFile();
    Enumeration<@NonNull ?> entries = archiveFile.entries();
    Set<String> traceFileNames = new HashSet<>();
    while (entries.hasMoreElements()) {
        ArchiveEntry entry = (ArchiveEntry) entries.nextElement();
        String entryName = entry.getName();
        IPath fullArchivePath = new Path(entryName);
        if (!fullArchivePath.hasTrailingSeparator() && fullArchivePath.segmentCount() > 0) {
            traceFileNames.add(fullArchivePath.segment(0));
        }
    }
    List<TracePackageElement> packageElements = new ArrayList<>();
    for (String traceFileName : traceFileNames) {
        TracePackageTraceElement traceElement = new TracePackageTraceElement(null, traceFileName, null);
        new TracePackageFilesElement(traceElement, traceFileName);
        packageElements.add(traceElement);
    }
    return packageElements.toArray(new TracePackageElement[] {});
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) 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) HashSet(java.util.HashSet)

Example 23 with TracePackageElement

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

the class TracePackageExtractManifestOperation method run.

/**
 * Run extract the manifest 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) {
    TracePackageElement[] elements = null;
    try {
        progressMonitor.worked(1);
        ArchiveFile archiveFile = getSpecifiedArchiveFile();
        progressMonitor.worked(1);
        if (archiveFile == null) {
            setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TracePackageExtractManifestOperation_InvalidFormat));
            return;
        }
        Enumeration<@NonNull ?> entries = archiveFile.entries();
        boolean found = false;
        while (entries.hasMoreElements()) {
            ModalContext.checkCanceled(progressMonitor);
            ArchiveEntry entry = (ArchiveEntry) entries.nextElement();
            IPath p = new Path(entry.getName());
            // Remove project name
            p = p.removeFirstSegments(1);
            if (entry.getName().endsWith(ITracePackageConstants.MANIFEST_FILENAME)) {
                found = true;
                InputStream inputStream = archiveFile.getInputStream(entry);
                ManifestReader.validateManifest(inputStream);
                inputStream = archiveFile.getInputStream(entry);
                elements = ManifestReader.loadElementsFromManifest(inputStream);
                break;
            }
            progressMonitor.worked(1);
        }
        if (found) {
            setStatus(Status.OK_STATUS);
        } else {
            elements = generateElementsFromArchive();
            if (elements.length > 0) {
                setStatus(Status.OK_STATUS);
            } else {
                setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, MessageFormat.format(Messages.TracePackageExtractManifestOperation_ErrorManifestNotFound, ITracePackageConstants.MANIFEST_FILENAME)));
            }
        }
        setResultElements(elements);
        archiveFile.close();
    } catch (InterruptedException e) {
        setStatus(Status.CANCEL_STATUS);
        Thread.currentThread().interrupt();
    } catch (Exception e) {
        setStatus(new Status(IStatus.ERROR, Activator.PLUGIN_ID, Messages.TracePackageExtractManifestOperation_ErrorReadingManifest, e));
    }
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) InputStream(java.io.InputStream) TracePackageElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)

Example 24 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement 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 25 with TracePackageElement

use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement 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)

Aggregations

TracePackageElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageElement)41 TracePackageTraceElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageTraceElement)26 TracePackageFilesElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageFilesElement)20 ArrayList (java.util.ArrayList)12 Element (org.w3c.dom.Element)11 RemoteImportProfileElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportProfileElement)9 IStatus (org.eclipse.core.runtime.IStatus)8 RemoteImportConnectionNodeElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportConnectionNodeElement)8 TracePackageExperimentElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.tracepkg.TracePackageExperimentElement)8 IPath (org.eclipse.core.runtime.IPath)7 Status (org.eclipse.core.runtime.Status)6 RemoteImportTraceGroupElement (org.eclipse.tracecompass.internal.tmf.remote.ui.wizards.fetch.model.RemoteImportTraceGroupElement)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 HashMap (java.util.HashMap)5 Path (org.eclipse.core.runtime.Path)5 Document (org.w3c.dom.Document)5 IFileStore (org.eclipse.core.filesystem.IFileStore)4