use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject in project tracecompass by tracecompass.
the class RemoteImportTracesOperation method copy.
private void copy(InputStream in, IFolder destFolder, IPath destination, SubMonitor monitor, long length) throws IOException {
IFolder intermediateTempFolder = null;
IFile tempFile = null;
File intermediateFile = null;
try {
intermediateTempFolder = fDestination.getProject().getResource().getFolder(TRACE_IMPORT);
if (intermediateTempFolder.exists()) {
intermediateTempFolder.delete(true, SubMonitor.convert(monitor));
}
intermediateTempFolder.create(true, true, SubMonitor.convert(monitor));
tempFile = intermediateTempFolder.getFile(destination.lastSegment());
tempFile.create(null, true, SubMonitor.convert(monitor));
intermediateFile = tempFile.getLocation().toFile();
Files.createFile(intermediateFile.toPath());
copy(in, intermediateFile, length, monitor);
if (ArchiveUtil.isArchiveFile(intermediateFile)) {
// Select all the elements in the archive
FileSystemObjectImportStructureProvider importProvider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null);
IFileSystemObject fileSystemObject = importProvider.getIFileSystemObject(intermediateFile);
TraceFileSystemElement rootTraceFileElement = TraceFileSystemElement.createRootTraceFileElement(fileSystemObject, importProvider);
// Select all the elements in the archive
List<TraceFileSystemElement> list = new ArrayList<>();
rootTraceFileElement.getAllChildren(list);
if (!destFolder.exists()) {
destFolder.create(true, true, SubMonitor.convert(monitor));
}
final IFolder folder = destFolder.getFolder(destination.lastSegment());
if (!folder.exists()) {
folder.create(true, true, SubMonitor.convert(monitor));
}
final TraceValidateAndImportOperation operation = new TraceValidateAndImportOperation(fShell, list, null, intermediateTempFolder.getLocation(), destFolder.getFullPath(), false, ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE | ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES, fDestination, null, null, null, false);
operation.setConflictHandler(fConflictHandler);
operation.run(SubMonitor.convert(monitor));
monitor.done();
} else {
// should be lightning fast unless someone maps different files
// to different physical disks. In windows and linux, moves are
// super fast on the same drive
Files.move(intermediateFile.toPath(), destination.toFile().toPath(), StandardCopyOption.REPLACE_EXISTING);
}
} catch (CoreException | InvocationTargetException e) {
Activator.getDefault().logError(e.getMessage(), e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
} finally {
try {
if (intermediateFile != null && intermediateFile.exists()) {
Files.delete(intermediateFile.toPath());
}
if (tempFile != null && tempFile.exists()) {
tempFile.delete(true, SubMonitor.convert(monitor));
}
if (intermediateTempFolder != null && intermediateTempFolder.exists()) {
intermediateTempFolder.delete(true, SubMonitor.convert(monitor));
}
} catch (CoreException e) {
Activator.getDefault().logError(e.getMessage(), e);
}
}
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject in project tracecompass by tracecompass.
the class HttpTraceImportOperation method execute.
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
int importOptionFlags = ImportTraceWizardPage.OPTION_IMPORT_UNRECOGNIZED_TRACES | ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
// Temporary directory to contain any downloaded files
IFolder tempDestination = fDestinationFolder.getProject().getResource().getFolder(TRACE_HTTP_IMPORT_TEMP_FOLDER);
String tempDestinationFolderPath = tempDestination.getLocation().toOSString();
if (tempDestination.exists()) {
tempDestination.delete(true, monitor);
}
tempDestination.create(IResource.HIDDEN, true, monitor);
// Download trace/traces
List<File> downloadedTraceList = new ArrayList<>();
TraceDownloadStatus status = DownloadTraceHttpHelper.downloadTraces(fSourceUrl, tempDestinationFolderPath);
if (status.isOk()) {
List<TraceDownloadStatus> children = status.getChildren();
for (TraceDownloadStatus traceDownloadStatus : children) {
downloadedTraceList.add(traceDownloadStatus.getDownloadedFile());
}
} else if (status.isTimeout()) {
if (tempDestination.exists()) {
tempDestination.delete(true, monitor);
}
throw new InterruptedException();
}
boolean isArchive = false;
if (!downloadedTraceList.isEmpty()) {
isArchive = ArchiveUtil.isArchiveFile(downloadedTraceList.get(0));
}
FileSystemObjectImportStructureProvider provider = null;
IFileSystemObject object = null;
String archiveFolderName = null;
if (isArchive) {
// If it's an archive there is only 1 element in this list
File downloadedTrace = downloadedTraceList.get(0);
Pair<IFileSystemObject, FileSystemObjectImportStructureProvider> rootObjectAndProvider = ArchiveUtil.getRootObjectAndProvider(downloadedTrace, null);
provider = rootObjectAndProvider.getSecond();
object = rootObjectAndProvider.getFirst();
archiveFolderName = downloadedTrace.getName();
} else {
provider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null);
object = provider.getIFileSystemObject(new File(tempDestinationFolderPath));
}
TraceFileSystemElement root = TraceFileSystemElement.createRootTraceFileElement(object, provider);
List<TraceFileSystemElement> fileSystemElements = new ArrayList<>();
root.getAllChildren(fileSystemElements);
IPath sourceContainerPath = new Path(tempDestinationFolderPath);
IPath destinationContainerPath = fDestinationFolder.getPath();
TraceValidateAndImportOperation validateAndImportOperation = new TraceValidateAndImportOperation(null, fileSystemElements, null, sourceContainerPath, destinationContainerPath, isArchive, importOptionFlags, fDestinationFolder, null, null, archiveFolderName, false);
validateAndImportOperation.run(monitor);
provider.dispose();
// Clean the temporary directory
if (tempDestination.exists()) {
tempDestination.delete(true, monitor);
}
}
use of org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject in project tracecompass by tracecompass.
the class TraceImportOperation method execute.
@Override
protected void execute(IProgressMonitor monitor) throws CoreException, InvocationTargetException, InterruptedException {
int importOptionFlags = ImportTraceWizardPage.OPTION_CREATE_LINKS_IN_WORKSPACE | ImportTraceWizardPage.OPTION_PRESERVE_FOLDER_STRUCTURE;
if (fSkipArchiveExtraction) {
importOptionFlags |= ImportTraceWizardPage.OPTION_SKIP_ARCHIVE_EXTRACTION;
}
if (fRenameConflictingTraces) {
importOptionFlags |= ImportTraceWizardPage.OPTION_RENAME_ALL;
} else {
importOptionFlags |= ImportTraceWizardPage.OPTION_OVERWRITE_EXISTING_RESOURCES;
}
if (fStartTimeRange != null && fEndTimeRange != null) {
importOptionFlags |= ImportTraceWizardPage.OPTION_FILTER_TIMERANGE;
}
IPath baseSourceContainerPath = new Path(fSourcePath);
IPath destinationContainerPath = fDestFolder.getPath();
FileSystemObjectImportStructureProvider provider = new FileSystemObjectImportStructureProvider(FileSystemStructureProvider.INSTANCE, null);
IFileSystemObject object = provider.getIFileSystemObject(new File(fSourcePath));
TraceFileSystemElement root = TraceFileSystemElement.createRootTraceFileElement(object, provider);
List<TraceFileSystemElement> fileSystemElements = new ArrayList<>();
root.getAllChildren(fileSystemElements);
final TraceValidateAndImportOperation importOperation = new TraceValidateAndImportOperation(null, fileSystemElements, null, baseSourceContainerPath, destinationContainerPath, false, importOptionFlags, fDestFolder, fStartTimeRange, fEndTimeRange, null, false);
try {
importOperation.run(monitor);
} catch (InvocationTargetException e) {
// $NON-NLS-1$
Activator.getDefault().logError("Error running trace import operation", e);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
monitor.done();
}
Aggregations