Search in sources :

Example 1 with IFileSystemObject

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);
        }
    }
}
Also used : FileSystemObjectImportStructureProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.FileSystemObjectImportStructureProvider) TraceFileSystemElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceFileSystemElement) IFile(org.eclipse.core.resources.IFile) ArrayList(java.util.ArrayList) InvocationTargetException(java.lang.reflect.InvocationTargetException) TraceValidateAndImportOperation(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceValidateAndImportOperation) CoreException(org.eclipse.core.runtime.CoreException) IFileSystemObject(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject) IFile(org.eclipse.core.resources.IFile) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 2 with IFileSystemObject

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);
    }
}
Also used : FileSystemObjectImportStructureProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.FileSystemObjectImportStructureProvider) TraceFileSystemElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceFileSystemElement) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) TraceValidateAndImportOperation(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceValidateAndImportOperation) IFileSystemObject(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject) TraceDownloadStatus(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceDownloadStatus) File(java.io.File) IFolder(org.eclipse.core.resources.IFolder)

Example 3 with IFileSystemObject

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();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) FileSystemObjectImportStructureProvider(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.FileSystemObjectImportStructureProvider) TraceFileSystemElement(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceFileSystemElement) TraceValidateAndImportOperation(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceValidateAndImportOperation) IPath(org.eclipse.core.runtime.IPath) ArrayList(java.util.ArrayList) IFileSystemObject(org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject) File(java.io.File) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Aggregations

File (java.io.File)3 ArrayList (java.util.ArrayList)3 FileSystemObjectImportStructureProvider (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.FileSystemObjectImportStructureProvider)3 IFileSystemObject (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.IFileSystemObject)3 TraceFileSystemElement (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceFileSystemElement)3 TraceValidateAndImportOperation (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceValidateAndImportOperation)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 IFolder (org.eclipse.core.resources.IFolder)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IFile (org.eclipse.core.resources.IFile)1 CoreException (org.eclipse.core.runtime.CoreException)1 TraceDownloadStatus (org.eclipse.tracecompass.internal.tmf.ui.project.wizards.importtrace.TraceDownloadStatus)1