1 /*******************************************************************************
2 * Copyright (c) 2015 Ericsson
4 * All rights reserved. This program and the accompanying materials are
5 * made available under the terms of the Eclipse Public License v1.0 which
6 * accompanies this distribution, and is available at
7 * http://www.eclipse.org/legal/epl-v10.html
10 * Marc-Andre Laperle - Initial API and implementation
11 *******************************************************************************/
13 package org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.wizards
.fetch
.model
;
16 import java
.io
.FileInputStream
;
18 import org
.eclipse
.core
.runtime
.IProgressMonitor
;
19 import org
.eclipse
.core
.runtime
.IStatus
;
20 import org
.eclipse
.core
.runtime
.Status
;
21 import org
.eclipse
.tracecompass
.internal
.tmf
.remote
.ui
.Activator
;
22 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.AbstractTracePackageOperation
;
23 import org
.eclipse
.tracecompass
.internal
.tmf
.ui
.project
.wizards
.tracepkg
.TracePackageElement
;
26 * An operation that extracts profiles information from a file
28 * @author Marc-Andre Laperle
30 public class ExtractRemoteProfilesOperation
extends AbstractTracePackageOperation
{
33 * Constructs a new import operation for reading the profiles
36 * the output file name
38 public ExtractRemoteProfilesOperation(String fileName
) {
43 * Run the extract profiles operation. The status (result) of the operation
44 * can be obtained with {@link #getStatus}
46 * @param progressMonitor
47 * the progress monitor to use to display progress and receive
48 * requests for cancellation
51 public void run(IProgressMonitor progressMonitor
) {
52 TracePackageElement
[] elements
= null;
54 progressMonitor
.worked(1);
55 File file
= new File(getFileName());
56 progressMonitor
.worked(1);
58 setStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, "Invalid format")); //$NON-NLS-1$
62 // TODO backwards compatibility for location
63 try (FileInputStream inputStream
= new FileInputStream(file
)) {
64 RemoteImportProfilesReader
.validate(inputStream
);
67 try (FileInputStream inputStream
= new FileInputStream(file
)) {
68 elements
= RemoteImportProfilesReader
.loadElementsFromProfiles(inputStream
);
71 progressMonitor
.worked(1);
73 setResultElements(elements
);
74 setStatus(Status
.OK_STATUS
);
75 } catch (Exception e
) {
76 setStatus(new Status(IStatus
.ERROR
, Activator
.PLUGIN_ID
, "Error reading profiles", e
)); //$NON-NLS-1$