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);
}
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[] {});
}
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));
}
}
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();
}
}
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;
}
Aggregations